Welcome to Raspbot V2 repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
5.Car patrol
05. Car patrol
05. Car patrol1. Learning objectives2. Experimental preparation3. Core code analysis4. Experimental phenomenon
1. Learning objectives
Control the car to patrol in the set direction.
2. Experimental preparation
As shown in the figure below, the motor needs to be connected to the expansion board.

3. Core code analysis
Car direction diagram
q w e
a--丨--d
z x c
McLumk_Wheel_Sports library function required to control the movement of the car:
xmove_forward(speed)
Parameter explanation: Control the car to move forward
speed: [0,255], the larger the value, the faster the forward speed
Return value: None.
xxxxxxxxxxmove_backward(speed)
Parameter explanation: Control the car to move backward
speed: [0,255], the larger the value, the faster the backward speed
Return value: None.
xxxxxxxxxxmove_right(speed)
Parameter explanation: Control the car to move right
speed: [0,255], the larger the value, the faster the right translation speed
Return value: None.
xxxxxxxxxxmove_left(speed)
Parameter explanation: Control the car to move left
speed: [0,255], the larger the value, the faster the left translation speed
Return value: None.
Source code path: project_demo/04.Car_motion_control
Library path: /home/pi/project_demo/lib
4. Experimental phenomenon
Turn on the robot, open the computer browser to enter the Jupyter lab editor
Enter the source code path, double-click the code to be run

Restart the kernel and clear all outputs

Click the first code block, then click the run button to start running one by one

After the program runs, as the code blocks run, we can see that the car moves forward for 1 second, moves right for 1.2 seconds, moves back for 1 second, moves left for 1.2 seconds, and finally stops. The path it has traveled is equivalent to a rectangle.