Welcome to Raspbot repository
5.7 Tracking
Tip:
In order to avoid sunlight affecting the infrared sensor, the experiment needs to be carried out indoors.
1. Learning target
In this course, we will learn how to use tracking module to make car completes tracking experiment.
2. Principle of experimental
The basic principle of the tracking sensor is to use the reflective nature of the object.
Our experiment is to tracking the black line. When the infrared light is emitted to the black line, it will be absorbed by the black line. When the infrared light is emitted to the other color line, it will reflected to the infrared receiver tube.
When detecting tracks of different shapes, the state of the 4-channel tracking sensor is as shown below.
For the Raspbot car, we use 4 TT DC gear motors. They are driven by the AT8236 chip. The driver chip is not directly connected to the Raspberry Pi pins.
Raspberry Pi communicates with STM8 MUC through IIC, and then STM8 MCU drives AT8236 chip to drive the motor.
3. Coding method
In this course, we use BOARD coding method.
According to the hardware interface manual, we see that the tracking module pins are connected to the 11,7,13,15 pin of the Raspberry Pi board.
STM8 is connected to SDA.1, SCL.1 on the Raspberry Pi board.
We have provided a library text dedicated to driving motors and servos --YB_Pcb_Car.py.
It is located in the same directory as the motor driver.
The pin comparison table of Raspberry Pi as shown below.
4. About code
Path: /home/pi/Yahboom_project/Raspbot/2.Hardware Control course/7.Ultrasonic avoid/Tracking test.ipynb
1) Import time and GPIO library
2)Set the GPIO coding mode, define tracking module pin and define the car class is used to drive motors or servos.
3) Read the value of the tracking module and print it out.
When we click the stop button, we exit the loop, stop the car, and clear the car class and GPIO.
5. Experimental phenomenon
After the program runs. Place the car on a dedicated black and white tracking map, adjust the knob of the tracking module to make indicator light is on when the sensor detects black, and indicator light is off when it detects white.
We can see that when black is detected, 0 is printed, and when white is detected, 1 is printed.
Path: /home/pi/Yahboom_project/Raspbot/2.Hardware Control course/7.Ultrasonic avoid/Tracking.ipynb
1) Import time, GPIO and YB_Pcb_Car library
2)Set the GPIO coding mode, define tracking module pin and define the car class is used to drive motors or servos.
3) Define the function of the tracking module
4) Call the tracking function in loop to complete the obstacle avoidance experiment.
When we click the stop button, we exit the loop, stop the car, and clear the car class and GPIO.
6. Experimental phenomenon
Before running the tracking experiment.
We need to adjust the sensitivity of the tracking module. The indicator light is off when white is detected, and the indicator light is on when black is detected.
After the program runs, place the car on the dedicated black and white tracking map, and the car will move along the black line.