1. 功能描述
用手机APP,通过WiFi通信遥控斜三角履带机械臂小车样机实现移动和搬运。
2. 电子硬件
在这个实验中,采用了以下硬件,请大家参考:
Basra主控板(兼容Arduino Uno)、Bigfish2.1扩展板、7.4V锂电池、WiFi无线路由器、2510通信转接板
为斜三角履带机械臂小车样机安装WiFi无线路由器和摄像头。
硬件连接步骤:
(1)在2510通信转接板的4针接口上,按如图方式插上3根杜邦线。
(2)杜邦线的另一端插接在WiFi模块的串口针上。
(3)连接USB线。
(4)将整套装置固定在样机上(注意:图中贴有黄色便条的MEGA2560主控板部分与本文所述功能无关,请忽略)。
3. 示例程序
编程环境:Arduino 1.8.19
手机APP的键值按上述规则进行配置,然后单片机接收到不同的信息,对应执行不同的动作。
例程代码(Rescue_Robot_Clear.ino)如下:
/********************************************************************* 版权说明:Copyright 2022 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved. Distributed under MIT license.See file LICENSE for detail or copy at https://opensource.org/licenses/MIT by 机器谱 2022-9-28 https://www.robotway.com/ ************************* wifi protocol **************************** * ff 00 xx 00 ff Controlled robot motion,xx :00 ~ 04 xx: 00:Stop 01:Forward 02:Backword 03:Left 04:Right * ff 02 01 xx ff left speed slider, adjust speed, xx : 0 ~ 10 * ff 02 02 xx ff right speed slider, operate panel, xx : 0 ~ 10 参考:WIFI机器人网·机器人创意工作室上位机与下位机通信协议(V1.1版) http://www.wifi-robots.com/thread-7051-1-1.html *************************** main process ***************************** __________________________ | \ start - wait mode - infrared start - automode 60s \ \ | \ ------------------ wifi mode - wait 10s \____________________________________| *************************** servo motor ****************************** 引脚 角度 机械手爪 D3 打开:90 夹取:60 机械手臂 D4 抬起:90 放下:60 注:上述舵机角度为本套程序使用的,可根据需求修改。 ********************************************************************/ #include <Servo.h> Servo servoX; Servo servoY; bool dataComplete; bool isPanelOpen; bool isPanelDown; int ServoMotorOpenD3 = 90; //舵机角度 int ServoMotorCloseD3 = 60; int ServoMotorUpD4 = 90; int ServoMotorDownD4 = 60; int moveDirection; // 1-forward, 2-backward, 3-left, 4-right, 5-stop int inputData[4]; //data from wifi int GripperDireciton; // 0 - close, 10 - open int DownDireciton; // 0 - Down, 10 - Up void setup() { Serial.begin(9600); servoX.attach(3); servoY.attach(4); isPanelOpen = false; isPanelDown = false; GripperDireciton = 10; DownDireciton = 10; } void loop() { WiFi_Rescue_Robot(); } void WiFi_Rescue_Robot() { WifiControl(); Move(moveDirection); } void WifiControl() { //control by wifi if (dataComplete) //接收完 WiFi 数据后 { //operate wheel if(inputData[0] == 0x00) { if(inputData[1] != moveDirection) { moveDirection = inputData[1]; } } //speed slider else if(inputData[0] == 0x02) { //adjust speed if(inputData[1] == 0x01) { if(inputData[2] != DownDireciton) { DownDireciton = inputData[2]; if(DownDireciton == 0 && !isPanelDown) { servoY.write(ServoMotorDownD4); isPanelDown = true; } else if(DownDireciton == 10 && isPanelDown) { servoY.write(ServoMotorUpD4); isPanelDown = false; } } } //operate panel else if(inputData[1] == 0x02) { if(inputData[2] != GripperDireciton) { GripperDireciton = inputData[2]; if(GripperDireciton == 0 && !isPanelOpen) { servoX.write(ServoMotorCloseD3); isPanelOpen = true; } else if(GripperDireciton == 10 && isPanelOpen) { servoX.write(ServoMotorOpenD3); isPanelOpen = false; } } } } } } void serialEvent() { static int i; static boolean revStart; while (Serial.available()) { //get data from wifi int inData = Serial.read(); if (inData == 0xff && !revStart) { revStart = true; } else if(revStart) { inputData[i] = inData; i++; if(i > 3) { if(inputData[3] == 0xff) { dataComplete = true; i = 0; revStart = false; } else { i = 0; revStart = false; } } } } } void Move(int direction) { switch (direction) { case 0x01:MoveForward();break; case 0x02:MoveBackward();break; case 0x03:MoveLeft();break; case 0x04:MoveRight();break; case 0x05:MoveStop();break; default:MoveStop();break; } } void MoveForward() { //motor_0 clockwise digitalWrite(5, LOW); digitalWrite(6, HIGH); //motor_1 clockwise digitalWrite(9, LOW); digitalWrite(10, HIGH); } void MoveBackward() { //motor_0 clockwise digitalWrite(5, HIGH); digitalWrite(6, LOW); //motor_1 clockwise digitalWrite(9, HIGH); digitalWrite(10, LOW); } void MoveRight() { //motor_0 clockwise digitalWrite(5, HIGH); digitalWrite(6, LOW); //motor_1 clockwise digitalWrite(9, LOW); digitalWrite(10, HIGH); } void MoveLeft() { //motor_0 clockwise digitalWrite(5, LOW); digitalWrite(6, HIGH); //motor_1 clockwise digitalWrite(9, HIGH); digitalWrite(10, LOW); } void MoveStop() { //motor_0 clockwise digitalWrite(5, HIGH); digitalWrite(6, HIGH); //motor_1 clockwise digitalWrite(9, HIGH); digitalWrite(10, HIGH); } |
4. 安卓手机APP设置及操作
(1)安装WIFIRobot.apk到安卓手机内。
(2)打开主控板的开关启动设备,并使用手机连接GL-AR150-xxx(xxx为随机数字与字母)密码:goodlife
(3)打开“WIFIROBOTS”APP。
(4)选择设置(以V1.06版界面为例,你也可以安装其他版本,设置方法相同)
(5)按照下图所示进行参数配置,点击确定
(6)点击前后左右可以控制救援机器人运动,如下图。
(7)点击速度调整可以打开调整面板,如下图。
(8)滑动写有左侧速度的控件,将其调整为0,可以控制清障手臂向下运动,如下图。
(9)将左侧速度的控件,调整为10,可以控制清障手臂向上运动,如下图。
(10)将右侧速度的控件,调整为0,可以控制清障手臂夹取障碍物,如下图。
(11)将右侧速度的控件,调整为10,可以控制清障手臂松开障碍物,如下图。
资料内容:WiFi遥控搬运-例程、WiFi无线路由器-安卓APK文件