User Manual
40
angle and small-angle turning. If the light is at the central left side (status [1,1,0]), we should apply
a small-angle turning; if the light is at the edge of the left side (status [1,0,0]), we should apply a
large-angle turning.
Code Explanation
To understand the code, take the software subflows above for reference.
Three Python modules are used in the code including the imported light_follower_module,
front_wheels, and back_wheel previously. They are drivers for this kit, respectively for light
following, front wheels and rear wheels.
The related classes have been defined here. When the modules are applied to use, objects
will be created for related classes, and different parts of hardware will be driven by calling a
function by the class object.
For example, for the light following module, we create an object named lf:
lf = Light_Follower.Light_Follower()
Then we can call the function by a class object.
A0 = lf.read_analog()[0]
This function read_analog() will return a list with three elements, which stores the detected
analog values of three probes. Here we use A0 = lf.read_analog()[0], A1 =
lf.read_analog()[1], and A2 = lf.read_analog()[2] to store three elements of returned
value separately into the variables A0-A2.
A for() loop is used here cycling 10 times, that is the car will acquire the analog values ten
times when the car drives in a circle under the calibration mode. The minimum values will be
taken as reference here. If you need more samples, just increase the times of the loop.
Store the detected values to a list in each loop by the env0_list.append(A0) function. When
the loop ends, the built-in list function reference[0] = min(env0_list) in Python will pick out
the minimum in the list.
lt_status_now = lf.read_flashlight()
This is to read the status of the module, which will return a 3-element list. This function is used
to solve the possible problem caused by brightness-adjustable flashlights. They blink
repeatedly due to brightness change by PWM method, so we add this function to the driver
library to prevent the car from moving and stopping repeatedly when the light source lights
up and goes out quickly or changes luminance by ON/OFF ratio.
fw.turn(turning_angle)
Function for front wheels steering. The main program will call this function if the front wheels
are applied for steering. The parameter is the turning angle.
bw.forward()