本帖最后由 机器谱 于 2023-8-23 09:29 编辑
1. 功能说明
本文示例将实现R023样机小型双轮差速底盘悬崖巡检的功能。在小型双轮差速底盘上安装一个检测装置,它可以由1个近红外传感器和1个灰度传感器组成。近红外传感器可以识别桌面,灰度传感器可以识别“悬崖”,让机器人沿着“悬崖”巡逻,既不远离,也不掉下去。
2. 电子硬件
在这个示例中,我们采用了以下硬件,请大家参考:
主控板 | Basra主控板(兼容Arduino Uno)
| 扩展板 | Bigfish2.1扩展板
| 传感器 | 近红外传感器
| 灰度传感器 | 电池 | 7.4V锂电池 |
电路连接:
① 近红外传感器连接在Bigfish扩展板的A0端口;灰度传感器连接在Bigfish扩展板的A4端口。
② 2个直流电机分别连在Bigfish扩展板的9,10接口和5,6接口。
3. 功能实现
编程环境:Arduino 1.8.19
下面提供一个小型双轮差速底盘悬崖巡检的参考例程(Cliff_avoidance_robot.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-07-19 https://www.robotway.com/
- ------------------------------*/
- /*************************************************************************************************************************************************
- 实验需求:
- 实现悬崖巡检机器人
- 实现思路:
- 程序的整体思路为:用近红外来检测停放小车的桌面,用灰度来检测悬崖。
- 当近红外持续触发时,说明小车在桌面,小车保持前进,如果灰度传感器触发,说明小车遇到悬崖,
- 小车先后退350毫秒,在左转350毫秒远离悬崖。如果近红外没有触发,说明小车也检测到了悬崖。否则,小车前进。
- *************************************************************************************************************************************************/
- /******************************************************************
- 实验接线:
- 近红外传感器接到A0(即14引脚);
- 灰度传感器接到A4(即18引脚);
- 直流电机1接5,6引脚;
- 直流电机2接9,10引脚;
- ******************************************************************/
- int _ABVAR_1_Near_infrared_sensor = 0 ;
- int _ABVAR_2_Grayscale_sensor = 0 ;
- boolean __ardublockDigitalRead(int pinNumber)
- {
- pinMode(pinNumber, INPUT);
- return digitalRead(pinNumber);
- }
- void forward();
- void back();
- void Cliff();
- void left();
- void setup()
- {
- pinMode( 10, OUTPUT);
- pinMode( 6, OUTPUT);
- pinMode( 5, OUTPUT);
- pinMode( 9, OUTPUT);
- _ABVAR_1_Near_infrared_sensor = 14 ;
- _ABVAR_2_Grayscale_sensor = 18 ;
- }
- void loop()
- {
- if (__ardublockDigitalRead(_ABVAR_1_Near_infrared_sensor))
- {
- Cliff(); //如果近红外没有触发,说明小车检测到了悬崖。
- }
- if (!( __ardublockDigitalRead(_ABVAR_2_Grayscale_sensor) ))
- {
- Cliff(); //如果灰度传感器触发,说明小车遇到悬崖,小车先后退350毫秒,在左转350毫秒远离悬崖。
- }
- else
- {
- forward();
- }
- }
- void back()
- {
- analogWrite(5 , 0);
- analogWrite(6 , 100);
- analogWrite(9 , 0);
- analogWrite(10 , 100);
- }
- void forward()
- {
- analogWrite(5 , 100);
- analogWrite(6 , 0);
- analogWrite(9 , 80);
- analogWrite(10 , 0);
- }
- void Cliff()
- {
- back();
- delay( 350 );
- left();
- delay( 350 );
- }
- void left()
- {
- analogWrite(5 , 100);
- analogWrite(6 , 0);
- analogWrite(9 , 0);
- analogWrite(10 , 100);
- }
复制代码
4. 资料下载
资料内容:悬崖巡检-程序源代码
资料下载地址:小型双轮差速底盘-悬崖巡检 https://www.robotway.com/h-col-113.html
|