Académique Documents
Professionnel Documents
Culture Documents
1) Switches
The controller board has 2 push button switches for user input. Each push button
switch is an active low input with a pull-up resistor to prevent indeterminate input
conditions. Pressing a push-button switch causes a low logic input on the associated
input. To Read switch input, Data direction of the port pin must be set to input.
Connections details of the switches are shown below:
2) LEDs
The controller board has 4 green LEDs for output indication. Each LED is an active
low output. A current-limit resistor prevents excessive diode current. Port Pin must
be set to output mode. Writing a low logic level to an LED output causes the
associated LED to turn on. Table shows the associated connection details of the
LEDs.
3) DC Motor
1
4) Servo Motor
The servo will move based on the pulses sent over the control wire, which set the
angle of the actuator arm. The servo expects a pulse every 20 ms in order to gain
correct information about the angle. The width of the servo pulse dictates the range
of the servo's angular motion. A servo pulse of 1.5 ms width will set the servo to its
"neutral" position, or 90°. Pulse width less than 1.5ms will set position left to neutral
or towards 0° and pulse width more than 1.5ms will set position Right to neutral or
towards 180°. Servo motor control signal details are shown below:
1. Control Strategy
Analog to digital conversion interrupt was used to obtain sensor reading. A single
Conversion sequence of eight sensors was set. 8 bit Resolution ATD was used
currently and 10 bit would latter be attempted to see if control could be improved.
Three PWM channel are used. Channel 0 & 1 is used to control the motor and
channel 2 is used to control steering servo motor.
Using the calculated position of car with respect to the black line, the car would be
moved towards the center line of the black line. The calculated position is continually
fed into a PID loop for Feedback control. The black line would be aligned always at
the middle of the sensor units. The front wheels would be steered with the sensors
data synchronously.
2
3. Finding Position of the black line
To compensate for the sensitivity difference of the sensors, they should be calibrated
against black and white region of the track before racing. Each sensor has its own
‘black’ and ‘White’ value. A compensation ratio can be calculated from these ‘black’
and ‘White’ values. It is scaling factor to be applied to future readings so that 0
would be obtained when each sensor is on white region and 255(for 8-bit ATD) when
each sensor is on black region.
After Analog to digital conversion sequence, the compensated eight sensor readings
would be sorted in descending order of value by Bubble sort. The sensors of the top
three reading would be on the black line. The top three of the sorted readings would
then be sorted again in ascending order of sensor index. The middle sensor among
the three sensors must be the closest to center of black line. The offset of the black
line from the middle sensor can be estimated by the difference of the other two
sensors' reading. The position of the center of the black line relative to the sensors is
consequently obtained.
Sensor Data
Compensation
Now value
3
Bubble Sort By Indices
Position data
The first two rows are sensor readings after calibration for black and white regions.
Compensation ratio for each sensor is calculated using equation given above. Next
‘Now value’ are the sensor readings when the car is racing and after an ATD
conversion Sequence has completed. Below that are the compensated sensor
readings, bounded by their respective ‘Black’ and ‘White’ values.
Since sensor 2, 3, 4 have very high readings, the black line would be somewhere
between them. Sensor 4 has a lower reading than sensor 2, so the center of the
black line would probably be between sensor 2 and sensor 3 with human reasoning.
The readings are sorted in descending order of value. The top three sensor readings
are sorted again in ascending order of sensor index, which is correlated to their
geometrical position. Each sensor is assigned a position number in ascending order.
For example, sensor 3 which is at the center of the seven sensors, has the number
1536. that means if the position of the center line of the black line is at ‘1536’,
Sensor 3 is exactly above the center line of black line and seven sensor units are
perfectly aligned with the black line.
Position of the center of the black line= (Index of ‘middle sensor’)*2*ATD resolution
In above demonstration,
4
It implies that the center line of the black line is between sensor 2 and sensor 3,
which matches with the conclusion by human reasoning. The algorithm is thus
verified.
Error = Position number of central sensor – Position of the center of black line.
‘Error’ indicates how far the sensor units are offset from the black line. In this
demonstration, Error = 1536-1449 =87. This error will be treated as the error term
in PID control. A larger error implies a larger steering is required.
4. PID Control
PID control will be used to control the turning of the steering servo.
The Ziegler-Nicholas method can be adopted to tune the PID parameters. The I and
D gains should be first set to zero and then the P gain should be increased until the
output of the loop started to oscillate. The P and D controls should be adjusted as
the table below.
Ziegler-Nicholas method
Control P Tr Td
P 0.5*Ke - -
PI 0.45*Ke Pe/1.2 -
PID 0.6*Ke Pe/2 Pe/8
5
Program flow
Start Up
Initialize ATD
Initialize PWM
Calibrate
Sensor
Delay (100ms)
Enable
interrupt
ATD interrupt
Find Position of
line