EasyManuals Logo

Freenove 4WD Smart Car Board for Raspberry Pi User Manual

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
Page #91 background imageLoading...
Page #91 background image
Need support? support.freenove.com
87
Chapter 5 Ultrasonic Obstacle Avoidance Car
www.freenove.com
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
for i in range(90,30,-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()
self.run_motor(L,M,R)
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()
self.run_motor(L,M,R)
ultrasonic=Ultrasonic()
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
ultrasonic.run()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be
executed.
PWM.setMotorModel(0,0,0,0)
ultrasonic.pwm_S.setServoPwm('0',90)
Result analysis
Let servo0 rotate back and forth to 30 degrees, 90 degrees and 150 degrees respectively. And the ultrasonic
module also follows the movement to measure the obstacle distance of these three angles.
When distances detected on the left>30cm, middle >30cm, right>30cm. It means that there is no obstacle
within 30cm. So the car move forward.
When distances detected on the left<30cm, middle <30cm, right<30cm, it means that the car enters a dead
end, so the car move back and turned back.
When distances detected on the left<30cm, middle <30cm, right>30cm. It means that there is an obstacle on
the left side of the car, so the car turn right.
When distances detected on the left>30cm, middle <30cm, right<30cm. It means that there is an obstacle on
the right side of the car, so the car turn left.

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove 4WD Smart Car Board for Raspberry Pi and is the answer not in the manual?

Freenove 4WD Smart Car Board for Raspberry Pi Specifications

General IconGeneral
BrandFreenove
Model4WD Smart Car Board for Raspberry Pi
CategoryMicrocontrollers
LanguageEnglish