User Manual
31
distance 13 cm less than 17
distance 10 cm less than 17
Read distance error
You may find that the distance measurement may be not that accurate. It doesn’t matter.
This 25kHz ultrasonic module is not a commonly used one, but one has a horizontal detecting
range of about 30~40 degrees. Thus the distance measured may be not so accurate, but that
small range provides convenience for obstacle avoidance. Besides, since the Raspberry Pi is
not a real-time operating system, the inaccurate time calculation will affect the accuracy of
distance measurement too. However, this ultrasonic module is precise enough for obstacle
avoidance.
Step 3. Run the Code
Now we have a general idea of the ultrasonic module’s effect after the test above. Let’s run
the code of the ultrasonic obstacle avoidance.
Get into the directory:
cd ~/SunFounder_PiCar-S/example/
Run the code:
python ultra_sonic_avoid.py
Get on the road!
The PiCar-S starts running now. Just place the car on the ground. It will follow the program to
turn when it detects an obstacle; if the obstacle is too close, it will move backwards, and turn
left/right. You can also modify the threshold of obstacle detecting range and that of moving
backwards in the code.
Software Flow
Run obstacle
avoidance
program
Start
Keyboard
Interrupt
Y
End
N
Avoid
obstacle
function