极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2236|回复: 0

小型平行履带底盘实现超声避障功能

[复制链接]
发表于 2023-3-15 09:25:14 | 显示全部楼层 |阅读模式
本帖最后由 机器谱 于 2023-3-15 09:25 编辑

1. 功能说明
    本实验使用的样机为R026a样机小型平行履带底盘。在样机前方安装1个 超声波传感器 ,如果遇到障碍,机器人后退、转向,否则机器人前进,实现机器人避障的效果。


2. 电子硬件
    在这个示例中,我们采用了以下硬件,请大家参考:

主控板Basra(兼容Arduino Uno)
扩展板Bigfish2.1
传感器超声波传感器

    两个直流电机连在D5,D6以及D9,D10接口上;超声波传感器连在A4接口上。



3. 示例程序
编程环境:Arduino 1.8.19
编写并烧录以下程序(text.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-02-10 https://www.robotway.com/                                    

  6. ------------------------------------------------------------------------------------*/

  7. int _ABVAR_1_i = 0 ;

  8. int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)

  9. {

  10.   long duration;

  11.   pinMode(trigPin, OUTPUT);

  12.   pinMode(echoPin, INPUT);

  13.   digitalWrite(trigPin, LOW);

  14.   delayMicroseconds(2);

  15.   digitalWrite(trigPin, HIGH);

  16.   delayMicroseconds(20);

  17.   digitalWrite(trigPin, LOW);

  18.   duration = pulseIn(echoPin, HIGH);

  19.   duration = duration / 59;

  20.   if ((duration < 2) || (duration > 300)) return false;

  21.   return duration;

  22. }



  23. void turnLeft();

  24. void forward();

  25. void back();


  26. void setup()

  27. {

  28.   pinMode( 10, OUTPUT);

  29.   pinMode( 6, OUTPUT);

  30.   pinMode( 5, OUTPUT);

  31.   pinMode( 9, OUTPUT);

  32.   digitalWrite( 19 , LOW );


  33. }


  34. void loop()

  35. {

  36.   _ABVAR_1_i = ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 19 , 18 ) ;

  37.   if (( ( ( _ABVAR_1_i ) <= ( 5 ) ) && ( ( _ABVAR_1_i ) > ( 0 ) ) ))

  38.   {

  39.     back();

  40.     delay( 1000 );

  41.     turnLeft();

  42.     delay( 1500 );

  43.   }

  44.   else

  45.   {

  46.     forward();

  47.   }

  48. }


  49. void forward()

  50. {

  51.   analogWrite(5 , 0);

  52.   analogWrite(6 , 165);

  53.   analogWrite(9 , 0);

  54.   analogWrite(10 , 165);

  55. }


  56. void back()

  57. {

  58.   analogWrite(5 , 165);

  59.   analogWrite(6 , 0);

  60.   analogWrite(9 , 165);

  61.   analogWrite(10 , 0);

  62. }


  63. void turnLeft()

  64. {

  65.   analogWrite(5 , 165);

  66.   analogWrite(6 , 0);

  67.   analogWrite(9 , 0);

  68.   analogWrite(10 , 165);

  69. }
复制代码

5. 资料内容
躲避悬崖-例程源代码

资料下载地址:https://www.robotway.com/h-col-114.html
想了解更多机器人开源项目资料请关注 机器谱网站 https://www.robotway.com
回复

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 12:33 , Processed in 0.039985 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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