极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2262|回复: 0

小型双轮差速底盘红外跟随功能的实现

[复制链接]
发表于 2023-8-7 10:43:06 | 显示全部楼层 |阅读模式
本帖最后由 机器谱 于 2023-8-7 10:43 编辑

1. 功能说明
       本文示例将实现R023样机小型双轮差速底盘跟随人移动的功能。在小型双轮差速底盘前方按下图所示安装3个 近红外传感器【https://www.robotway.com/h-col-137.html】,制作一个红外线发射源,实现当红外发射源在机器人的检测范围内任意放置或移动时,机器人能追踪该发射源。



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

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

电路连接:
① 三个近红外传感器从左至右分别连接在Bigfish扩展板的A0,A4,A3端口。
② 左轮直流电机连在Bigfish扩展板的D9,D10接口;右轮直流电机连在Bigfish扩展板的D5,D6接口。


3. 功能实现
编程环境:Arduino 1.8.19
下面提供一个小型双轮差速底盘跟随人移动的参考例程(Infrareda_following.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-20 https://www.robotway.com/
  6.   ------------------------------*/
  7. void Right();
  8. void Left();
  9. void Stop();
  10. void Back();
  11. void Forward();

  12. void setup()
  13. {
  14.   pinMode( 17, INPUT);
  15.   pinMode( 18, INPUT);
  16.   pinMode( 14, INPUT);
  17.   pinMode( 10, OUTPUT);
  18.   pinMode( 6, OUTPUT);
  19.   pinMode( 5, OUTPUT);
  20.   pinMode( 9, OUTPUT);
  21. }

  22. void loop()
  23. {
  24.   if (!( digitalRead(18) ))
  25.   {
  26.     Stop();
  27.   }
  28.   if (!( digitalRead(14) ))
  29.   {
  30.     Right();
  31.   }
  32.   if (!( digitalRead(17) ))
  33.   {
  34.     Left();
  35.   }
  36.   if (digitalRead(18))
  37.   {
  38.     Forward();
  39.   }
  40. }

  41. void Left()
  42. {
  43.   analogWrite(5 , 0);
  44.   analogWrite(6 , 0);
  45.   analogWrite(9 , 0);
  46.   analogWrite(10 , 100);
  47. }

  48. void Stop()
  49. {
  50.   analogWrite(5 , 0);
  51.   analogWrite(6 , 0);
  52.   analogWrite(9 , 0);
  53.   analogWrite(10 , 0);
  54. }

  55. void Forward()
  56. {
  57.   analogWrite(5 , 0);
  58.   analogWrite(6 , 125);
  59.   analogWrite(9 , 0);
  60.   analogWrite(10 , 100);
  61. }

  62. void Back()
  63. {
  64.   analogWrite(5 , 125);
  65.   analogWrite(6 , 0);
  66.   analogWrite(9 , 100);
  67.   analogWrite(10 , 0);
  68. }

  69. void Right()
  70. {
  71.   analogWrite(5 , 0);
  72.   analogWrite(6 , 125);
  73.   analogWrite(9 , 0);
  74.   analogWrite(10 , 0);
  75. }
复制代码

4. 资料下载

资料内容:红外跟随-程序源代码
资料下载地址:小型双轮差速底盘-红外跟随 https://www.robotway.com/h-col-113.html
回复

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-5-1 23:53 , Processed in 0.038813 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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