本文示例所实现的功能为:采用蓝牙远程遥控双节履带机械臂小车进行运动。


在这个示例中,我们采用了以下硬件,请大家参考:
| 主控板 | Basra主控板(兼容Arduino Uno) |
| 扩展板 | Bigfish2.1扩展板 |
| 通信 | |
| 电池 | 7.4V锂电池 |
将文末资料中的“蓝牙串口助手.apk”安装到安卓手机中。将蓝牙模块连接到主控板并打开电源,然后在手机上运行蓝牙串口助手。

| 按钮名称 | 发送内容 |
| 下撑 | 0@0:0=0(90,90,201,201,30);@ |
| 平铺 | 0@0:0=0(90,90,201,201,90);@ |
| 上撑 | 0@0:0=0(90,90,201,201,150);@ |
| 放下 | 0@0:0=0(90,90,10,201,201);@ |
| 前进 | 0@0:0=0(70,110,201,201,201);@ |
| 抬起 | 0@0:0=0(90,90,40,201,201);@ |
| 左转 | 0@0:0=0(110,110,201,201,201);@ |
| 停止 | 0@0:0=0(90,90,201,201,201);@ |
| 右转 | 0@0:0=0(70,70,201,201,201);@ |
| 打开 | 0@0:0=0(90,90,201,150,201);@ |
| 后退 | 0@0:0=0(110,70,201,201,201);@ |
| 夹取 | 0@0:0=0(90,90,201,100,201);@ |
编程环境:Arduino 1.8.19 下面提供一个蓝牙远程遥控双节履带机械臂小车运动的参考程序(EODrobot.ino):
- /*------------------------------------------------------------------------------------
- 版权说明:Copyright 2023 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 机器谱 2023-09-04 https://www.robotway.com/
- ------------------------------*/
-
- #include
-
- #include
-
- #include
-
- #include
-
- #include
-
-
- String serialString = "";
-
- boolean serialComplete = false;
-
- char stringBuf[100];
-
- Protocol protocol;
-
- Servo myServo[5];
-
- int data[5];
-
- int olddata[5];
-
- int port[5] = {7,8,12,11,3};
-
- void setup()
-
- {
-
- Serial.begin(9600);
-
-
-
- for(int i = 0; i < 5; i++){
-
- data[i] = 201;
-
- myServo[i].attach(port[i]);
-
- }
-
- myServo[0].write(90);
-
- myServo[1].write(90);
-
- myServo[2].write(10);
-
- myServo[3].write(150);
-
- myServo[4].write(90);
-
- }
-
-
- void loop()
-
- {
-
- if (serialComplete) {
-
- protocol.Analyze(serialString);
-
- for(int i = 0; i < 5; i++)
-
- data[i] = protocol.parameter.GetAt(i);
-
- serialString = "";
-
- serialComplete = false;
-
-
-
-
-
- for(int i = 0; i < 5; i++){
-
- if(olddata[i] != data[i]){
-
- if(data[i] == 201)
-
- continue;
-
- else if(data[i] > 0 && data[i] < 180){
-
- myServo[i].write(data[i]);
-
- }
-
- olddata[i] = data[i];
-
- }
-
- }
-
- }
-
- }
-
-
- void serialEvent() {
-
- while (Serial.available()) {
-
- char inChar = (char)Serial.read();
-
- serialString += inChar;
-
- if (inChar == '\n') {
-
- serialComplete = true;
-
- }
-
- }
-
- }
-
-
程序源代码、样机3D文件以及蓝牙串口助手.apk等资料详见 双节履带机械臂小车-蓝牙遥控