EasyManua.ls Logo

Freenove 4WD Smart Car Board for Raspberry Pi - Chapter 5 Ultrasonic Obstacle Avoidance Car; Description; Run Program

Default Icon
132 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Need support? support.freenove.com
86
Chapter 5 Ultrasonic Obstacle Avoidance Car
Chapter 5 Ultrasonic Obstacle Avoidance Car
If you have any concerns, please feel free to contact us via support@freenove.com
Description
The obstacle avoidance function of the car mainly uses the HC-SR04 ultrasonic module. The ultrasonic module
is controlled by the servo. The servo rotates to the left, middle and right repeatedly, so that the ultrasonic
module measures the distance of obstacles on the left, middle and right directions. And then it controls the
car to move according to different distances.
Run program
If the terminal displays the directory as below, you can directly run the Ultrasonic.py.
1. If not, execute the cd command:
cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server
2. Run Ultrasonic.py:
sudo python Ultrasonic.py
You can press "Ctrl + C" to end the program.
Part of code is as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
def run(self):
self.PWM=Motor()
self.pwm_S=Servo()
for i in range(30,151,60):
self.pwm_S.setServoPwm('0',i)
time.sleep(0.2)
if i==30:
L = self.get_distance()
elif i==90:
M = self.get_distance()
else:
R = self.get_distance()
while True: