1. Function description
The example in this article will realize the function of the R023 prototype small two-wheel differential chassis to follow people. Install three near-infrared sensors in front of the small two-wheel differential chassis as shown in the figure below to create an infrared emission source, so that when the infrared emission source is placed or moved arbitrarily within the detection range of the robot, the robot can track the emission source.
2. Electronic hardware
In this example, we use the following hardware, please refer to it:
Main control board | |
expanding board | Bigfish2.1 expansion board |
sensor |
|
Battery | 7.4V lithium battery |
Circuit connection:
① Three near-infrared sensors are connected to the A0, A4, and A3 ports of the Bigfish expansion board from left to right.
② The left wheel DC motor is connected to the D9 and D10 interfaces of the Bigfish expansion board; the right wheel DC motor is connected to the D5 and D6 interfaces of the Bigfish expansion board.
3. Function implementation
Programming environment: Arduino 1.8.19
The following provides a reference routine for a small two-wheel differential chassis to follow people (Infrareda_following.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-07-20 https://www.robotway.com/
------------------------------*/
void Right();
void Left();
void Stop();
void Back();
void Forward();
void setup()
{
pinMode( 17, INPUT);
pinMode( 18, INPUT);
pinMode( 14, INPUT);
pinMode( 10, OUTPUT);
pinMode( 6, OUTPUT);
pinMode( 5, OUTPUT);
pinMode( 9, OUTPUT);
}
void loop()
{
if (!( digitalRead(18) ))
{
Stop();
}
if (!( digitalRead(14) ))
{
Right();
}
if (!( digitalRead(17) ))
{
Left();
}
if (digitalRead(18))
{
Forward();
}
}
void Left()
{
analogWrite(5 , 0);
analogWrite(6 , 0);
analogWrite(9 , 0);
analogWrite(10 , 100);
}
void Stop()
{
analogWrite(5 , 0);
analogWrite(6 , 0);
analogWrite(9 , 0);
analogWrite(10 , 0);
}
void Forward()
{
analogWrite(5 , 0);
analogWrite(6 , 125);
analogWrite(9 , 0);
analogWrite(10 , 100);
}
void Back()
{
analogWrite(5 , 125);
analogWrite(6 , 0);
analogWrite(9 , 100);
analogWrite(10 , 0);
}
void Right()
{
analogWrite(5 , 0);
analogWrite(6 , 125);
analogWrite(9 , 0);
analogWrite(10 , 0);
}
Infrared following - program source code information content, please refer to the small two-wheel differential chassis - infrared following