User Manual
51
Calibration
Run light
following
program
Start
Interrupt
Y
End
Run light follower
calibration function
Light following
subfunction
Detect obstacles
avoid_flag == 2
If an obstacle
detected, move
backwards
Else
If no obstacle found,
keep following light
avoid_flag == 1
If close to an
obstacle, turn away
N
Since the light following and obstacle avoidance of the car depend on the sensor modules,
we set two functions to read the status of two sensors separately, and assign values to flags to
be returned from the functions: state_light(), and state_sonic().
In the function state_sonic(), the return value is avoid_flag.
If the car is close to an obstacle, it will return avoid_flag = 2;
if it is too close to the obstacle, it will return avoid_flag = 1;
if ahead no obstacle is detected near, it will return avoid_flag = 0.
In the function state_light(), the return value is light_flag.
If the light spot is in front of the car, it will return light_flag = 0;
if the spot is at the right side, it will return light_flag = 1;