本帖最后由 机器谱 于 2023-3-17 09:33 编辑
1. 功能说明
本实验使用的样机为R026a样机小型平行履带底盘。在样机前方安装1个 近红外传感器 ,如果遇到障碍,机器人后退,否则机器人前进,实现机器人避障的效果。
2. 电子硬件
在这个示例中,我们采用了以下硬件,请大家参考:
主控板 | Basra(兼容Arduino Uno) | 扩展板 | Bigfish2.1 | 传感器 | 近红外传感器 | 电池 | 7.4V锂电池 |
两个直流电机连在D5,D6以及D9,D10接口上;近红外传感器连在A4接口上。
3. 示例程序
编程环境:Arduino 1.8.19
编写并烧录以下程序(infrared_car.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-02-10 https://www.robotway.com/
- ------------------------------
- 实验接线:两个直流电机接口的针脚号分别为D5,D6以及D9,D10;近红外传感器连在A4接口上
- ------------------------------------------------------------------------------------*/
- void setup()
- {
- pinMode( 18, INPUT);
- pinMode( 5 , OUTPUT);
- pinMode( 6 , OUTPUT);
- pinMode( 9 , OUTPUT);
- pinMode( 10 , OUTPUT);
- }
- void loop()
- {
- //如果传感器遇到障碍,后退,否则前进
- if (!( digitalRead(18) ))
- {
- digitalWrite( 5 , HIGH );
- digitalWrite( 6 , LOW );
- digitalWrite( 9 , HIGH );
- digitalWrite( 10 , LOW );
- }
- else
- {
- digitalWrite( 5 , LOW );
- digitalWrite( 6 , HIGH );
- digitalWrite( 9 , LOW );
- digitalWrite( 10 , HIGH );
- }
- }
复制代码
4. 资料下载
资料内容:红外避障-例程源代码
资料下载地址:https://www.robotway.com/h-col-114.html
想了解更多机器人开源项目资料请关注 机器谱网站 https://www.robotway.com
|