极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1828|回复: 0

小型双轮差速底盘实现悬崖巡检功能

[复制链接]
发表于 2023-8-23 09:29:39 | 显示全部楼层 |阅读模式
本帖最后由 机器谱 于 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):
  1. /*------------------------------------------------------------------------------------
  2.   版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.
  3.            Distributed under MIT license.See file LICENSE for detail or copy at
  4.            https://opensource.org/licenses/MIT
  5.            by 机器谱 2023-07-19 https://www.robotway.com/
  6.   ------------------------------*/
  7. /*************************************************************************************************************************************************
  8. 实验需求:
  9. 实现悬崖巡检机器人
  10. 实现思路:
  11. 程序的整体思路为:用近红外来检测停放小车的桌面,用灰度来检测悬崖。
  12. 当近红外持续触发时,说明小车在桌面,小车保持前进,如果灰度传感器触发,说明小车遇到悬崖,
  13. 小车先后退350毫秒,在左转350毫秒远离悬崖。如果近红外没有触发,说明小车也检测到了悬崖。否则,小车前进。
  14. *************************************************************************************************************************************************/


  15. /******************************************************************
  16. 实验接线:
  17. 近红外传感器接到A0(即14引脚);
  18. 灰度传感器接到A4(即18引脚);
  19. 直流电机1接5,6引脚;
  20. 直流电机2接9,10引脚;
  21. ******************************************************************/

  22. int _ABVAR_1_Near_infrared_sensor = 0 ;
  23. int _ABVAR_2_Grayscale_sensor = 0 ;
  24. boolean __ardublockDigitalRead(int pinNumber)
  25. {
  26.   pinMode(pinNumber, INPUT);
  27.   return digitalRead(pinNumber);
  28. }



  29. void forward();
  30. void back();
  31. void Cliff();
  32. void left();

  33. void setup()
  34. {
  35.   pinMode( 10, OUTPUT);
  36.   pinMode( 6, OUTPUT);
  37.   pinMode( 5, OUTPUT);
  38.   pinMode( 9, OUTPUT);
  39.   _ABVAR_1_Near_infrared_sensor = 14 ;

  40.   _ABVAR_2_Grayscale_sensor = 18 ;

  41. }

  42. void loop()
  43. {
  44.   if (__ardublockDigitalRead(_ABVAR_1_Near_infrared_sensor))
  45.   {
  46.     Cliff();   //如果近红外没有触发,说明小车检测到了悬崖。
  47.   }
  48.   if (!( __ardublockDigitalRead(_ABVAR_2_Grayscale_sensor) ))
  49.   {
  50.     Cliff();   //如果灰度传感器触发,说明小车遇到悬崖,小车先后退350毫秒,在左转350毫秒远离悬崖。
  51.   }
  52.   else
  53.   {
  54.     forward();
  55.   }
  56. }

  57. void back()
  58. {
  59.   analogWrite(5 , 0);
  60.   analogWrite(6 , 100);
  61.   analogWrite(9 , 0);
  62.   analogWrite(10 , 100);
  63. }

  64. void forward()
  65. {
  66.   analogWrite(5 , 100);
  67.   analogWrite(6 , 0);
  68.   analogWrite(9 , 80);
  69.   analogWrite(10 , 0);
  70. }

  71. void Cliff()
  72. {
  73.   back();
  74.   delay( 350 );
  75.   left();
  76.   delay( 350 );
  77. }

  78. void left()
  79. {
  80.   analogWrite(5 , 100);
  81.   analogWrite(6 , 0);
  82.   analogWrite(9 , 0);
  83.   analogWrite(10 , 100);
  84. }


复制代码

4. 资料下载
资料内容:悬崖巡检-程序源代码
资料下载地址:小型双轮差速底盘-悬崖巡检 https://www.robotway.com/h-col-113.html



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-2 05:00 , Processed in 0.043179 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表