User Manual
32
The ultrasonic module returns a digital value, i.e., High or Low level, and the interval time
between two levels returned can be converted to the distance to the obstacle. Thus, we call
the time module in Python for timing here. The formula to calculate the distance is written in
the ultrasonic module’s driver. The main program just calls the corresponding program to get
the distance value.
Subflow of the Obstacle Avoidance Function
When the car starts, it will detect obstacles and measure the distance in cycle, make
judgement, and take actions. Here are three cases: when the distance to the obstacle is x
(the ranging distance threshold) away, the car will turn directions; when the distance is less
than x, the car will move backwards before turning direction; when the distance is more than
x, it will keep moving forwards.
Avoid obstacle function
distance
detect
Touch
Backwards
Near by
Turns
More than
Forward
Loop