Welcome to Raspbot repository
5.8 Restricting
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 restricting 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.
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.
The pin comparison table of Raspberry Pi as shown below.
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.

4. About code
Path: /home/pi/Yahboom_project/Raspbot/2.Hardware Control course/7.Ultrasonic avoid/Tracking test.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 restricting function
4)Call the restricting 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 within the range of the black line on the white background. When the car encounters the black line, it will turn around and always keep moving within the range of the black line.