本帖最后由 机器谱 于 2022-12-26 10:05 编辑
1. 功能描述 本文提供的示例所实现的功能为:用手机APP遥控样机实现移动和搬运。 通过手机APP遥控样机完成将工作区外的工件搬运至工作区的任务,来模拟机器人的搬运过程。首先手机遥控机器人找到未存放在工作区内的工件,然后利用机械爪将工件夹起并保持工件处于夹持状态,最后将工件搬运至工作区即算完成任务。
2. 所用样机
在这个示例中,采用了以下硬件,请大家参考:
主控板 | Basra(兼容Arduino Uno) | 扩展板 | Bigfish2.1 | 电池 | 7.4V锂电池 | 通信 | 蓝牙串口模块
|
为样机安装好电子模块,将关节模块的舵机线连接到D12端口,机械爪的舵机线连接到D11端口。SH-01扩展板的直流电机接口组合是5/9,6/10,分别接左侧车轮电机和右侧车轮电机。
4. 示例程序 编程环境:Arduino 1.8.19 程序通过使用if语句来判断读取到的串口的不同字符值来匹配不同的动作,从而实现对机器人的远程控制。 接收到“1”的时候,执行前进; 接收到“3”的时候,执行左转; 接收到“4”的时候,执行右转; 接收到“5”的时候,执行停止; 接收到“6”的时候,机械爪闭合; 接收到“7”的时候,机械爪张开; 接收到“8”的时候,机械臂抬起; 接收到“9”的时候,机械臂放下;
手机APP的键值按上述规则进行配置,配置方法请参考蓝牙串口模块【https://www.robotway.com/h-col-141.html】。
例程代码(R214e_Bluetooth_RC.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-10-26 https://www.robotway.com/
- ------------------------------
- 实现功能: 从串口(蓝牙)接收字符,根据不同字符分别做出前进、原地左转、原地右转、夹爪打开、夹爪闭合、关节抬起、关节放下的动作。
- -----------------------------------------------------
- 实验接线:
- 关节:D12
- 机械爪:D11
- 左轮:D5,D9
- 右轮:D10,D6。
- ------------------------------------------------------------------------------------*/
- #include <Servo.h>
- int _ABVAR_1_data = 0 ;
- Servo servo_pin_11;
- Servo servo_pin_12;
- void tai();
- void zhua();
- void stop();
- void fang();
- void jiang();
- void turnright();
- void turnleft();
- void go();
- void setup()
- {
- pinMode( 10, OUTPUT);
- pinMode( 6, OUTPUT);
- pinMode( 5, OUTPUT);
- pinMode( 9, OUTPUT);
- Serial.begin(9600);
- servo_pin_11.attach(11);
- servo_pin_12.attach(12);
- }
- void loop()
- {
- _ABVAR_1_data = Serial.parseInt() ;
- if (( ( _ABVAR_1_data ) == ( 1 ) ))
- {
- go();
- }
- if (( ( _ABVAR_1_data ) == ( 3 ) ))
- {
- turnright();
- }
- if (( ( _ABVAR_1_data ) == ( 4 ) ))
- {
- turnleft();
- }
- if (( ( _ABVAR_1_data ) == ( 5 ) ))
- {
- stop();
- }
- if (( ( _ABVAR_1_data ) == ( 6 ) ))
- {
- zhua();
- }
- if (( ( _ABVAR_1_data ) == ( 7 ) ))
- {
- fang();
- }
- if (( ( _ABVAR_1_data ) == ( 8 ) ))
- {
- tai();
- }
- if (( ( _ABVAR_1_data ) == ( 9 ) ))
- {
- jiang();
- }
- }
- void zhua()
- {
- servo_pin_11.write( 63 );
- }
- void fang()
- {
- servo_pin_11.write( 80 );
- }
- void go()
- {
- analogWrite(5 , 80);
- analogWrite(9 , 0);
- analogWrite(6 , 80);
- analogWrite(10 , 0);
- }
- void jiang()
- {
- servo_pin_12.write( 75 );
- }
- void turnleft()
- {
- analogWrite(5 , 0);
- analogWrite(9 , 0);
- analogWrite(6 , 80);
- analogWrite(10 , 0);
- }
- void turnright()
- {
- analogWrite(5 , 80);
- analogWrite(9 , 0);
- analogWrite(6 , 0);
- analogWrite(10 , 0);
- }
- void tai()
- {
- servo_pin_12.write( 30 );
- }
- void stop()
- {
- analogWrite(5 , 255);
- analogWrite(9 , 255);
- analogWrite(6 , 255);
- analogWrite(10 , 255);
- }
复制代码
5.资料下载
资料内容:
① 蓝牙遥控例程源代码
② 蓝牙串口助手(新版)
资料下载链接:https://www.robotway.com/h-col-150.html
|