本帖最后由 机器谱 于 2023-5-24 10:55 编辑
1. 功能说明
在R023e机器人车体上安装1个 近红外传感器【https://www.robotway.com/h-col-137.html】 ,实现机器人小车避障功能。
2. 电子硬件
在这个示例中,我们采用了以下硬件,请大家参考:
主控板 | Basra主控板(兼容Arduino Uno)
| 扩展板 | Bigfish2.1扩展板
| 传感器 | 近红外传感器 | 电池 | 7.4V锂电池 |
电路连接说明:
① 2个电机分别连在Bigfish扩展板的D6,D10及D5,D9接口上;
② 近红外传感器接在Bigfish扩展板的A0端口上。
3. 功能实现
编程环境:Arduino 1.8.19
实现思路:在机器人前方放置障碍物,当机器人前方检测到有障碍物时,实现机器人右转后再前进2s躲避障碍物;否则机器人继续直行,以此来模拟汽车避障过程。
将参考例程(sketch_apr25a.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-04-25 https://www.robotway.com/
- ------------------------------*/
- void forward();
- void turnright();
- void carstop();
- void setup()
- {
- pinMode( 14, INPUT);
- pinMode( 10, OUTPUT);
- pinMode( 6, OUTPUT);
- pinMode( 5, OUTPUT);
- pinMode( 9, OUTPUT);
- }
- void loop()
- {
- if (!( digitalRead(14) ))
- {
- turnright();
- delay( 1000 );
- forward();
- delay( 2000 );
- carstop();
- delay( 5000 );
- }
- else
- {
- forward();
- }
- }
- void turnright()
- {
- analogWrite(6 , 80);
- analogWrite(10 , 0);
- analogWrite(5 , 0);
- analogWrite(9 , 80);
- }
- void forward()
- {
- analogWrite(6 , 80);
- analogWrite(10 , 0);
- analogWrite(5 , 80);
- analogWrite(9 , 0);
- }
- void carstop()
- {
- analogWrite(6 , 0);
- analogWrite(10 , 0);
- analogWrite(5 , 0);
- analogWrite(9 , 0);
- }
复制代码
4. 资料下载
资料内容:
①红外避障-程序源代码
②红外避障-样机3D文件
资料下载地址:https://www.robotway.com/h-col-113.html
想了解更多机器人开源项目资料请关注 机器谱网站 https://www.robotway.com
|