极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1995|回复: 0

小型平行履带底盘实现双灰度循迹功能

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

1. 功能说明
    在小型平行履带底盘样机上安装2个 灰度传感器 ,实现机器人沿指定路线进行运动的效果。


2. 使用样机
    本实验使用的样机为R026a样机。


3. 功能实现
3.1 电子硬件
在这个示例中,我们采用了以下硬件,请大家参考:

主控板Basra(兼容Arduino Uno)
扩展板Bigfish2.1
传感器灰度传感器
电池7.4V锂电池

3.2 编写程序
编程环境:Arduino 1.8.19

编写并烧录以下程序(2gray_blackline.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-09 https://www.robotway.com/

  6.   ------------------------------

  7.   实验接线:两个直流电机接口的针脚号分别为D5,D6以及D9,D10;灰度传感器连在A0、A4接口上                                    

  8. ------------------------------------------------------------------------------------*/

  9. int i=0;

  10. void Forward();

  11. void Back();

  12. void Turn_left();

  13. void Turn_right();

  14. void Speed_up();

  15. void Slow_down();

  16. void setup() {

  17.   // put your setup code here, to run once:

  18. pinMode(A0,INPUT);

  19. pinMode(A4,INPUT);

  20. pinMode(9,OUTPUT);

  21. pinMode(10,OUTPUT);

  22. pinMode(5,OUTPUT);

  23. pinMode(6,OUTPUT);

  24. Serial.begin(9600);

  25. }

  26. void loop() {

  27.   // put your main code here, to run repeatedly:

  28. int a=digitalRead(A0);

  29. int b=digitalRead(A4);

  30. Serial.println(a);

  31. Serial.println(b);//Here is serial monitor,you will kown in later learning

  32. if(a==0&&b==0)

  33. Forward();

  34. if(a==1&&b==0)

  35. Turn_left();

  36. if(a==0&&b==1)

  37. Turn_right();

  38. }

  39. void Forward()//

  40. {

  41. analogWrite(9,120);

  42. analogWrite(10,0);

  43. analogWrite(5,120);

  44. analogWrite(6,0);

  45. delay(50);

  46. }

  47. void Back()

  48. {

  49. digitalWrite(9,LOW);

  50. digitalWrite(10,HIGH);

  51. digitalWrite(5,LOW);

  52. digitalWrite(6,HIGH);

  53. delay(4000);

  54. }

  55. void Turn_left()

  56. {

  57. digitalWrite(9,0);

  58. digitalWrite(10,0);

  59. digitalWrite(5,100);

  60. digitalWrite(6,0);

  61. delay(50);

  62. }

  63. void Turn_right()

  64. {

  65. digitalWrite(9,100);

  66. digitalWrite(10,0);

  67. digitalWrite(5,0);

  68. digitalWrite(6,0);

  69. delay(50);

  70. }

  71. void Speed_up()

  72. {

  73. for(i=0;i<=255;i+=5)

  74.   {

  75.   analogWrite(9,i);

  76.   analogWrite(10,0);

  77.   analogWrite(5,i);

  78.   analogWrite(6,0);

  79.   delay(50);

  80.   }//speed up


  81. }

  82. void Slow_down()

  83. {

  84. for(i=255;i>=0;i-=5)

  85.   {  

  86.   analogWrite(9,i);

  87.   analogWrite(10,0);

  88.   analogWrite(5,i);

  89.   analogWrite(6,0);

  90.   delay(50);

  91.   }

  92. }
复制代码

4. 资料下载
资料内容:
灰度循迹-例程源代码
​资料下载地址:https://www.robotway.com/h-col-114.html

想了解更多机器人开源项目资料请关注 机器谱网站 https://www.robotway.com
回复

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 21:52 , Processed in 0.060270 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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