Vous êtes sur la page 1sur 6

Smart car race

Smart Car controller Board

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:

Switch 1 Port P Pin 5


Switch 2 Port P Pin 7

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.

LED 1 Port T Pin 4


LED 2 Port T Pin 5
LED 3 Port T Pin 6
LED 4 Port T Pin 7

3) DC Motor

DC motor is driven by Freescale MC33931VW H-bridge motor driver. DC motor will


rotate according to the voltage difference applied between its 2 terminals. The
polarity of the applied voltage will change the direction of rotation. Using PWM signal
we can change voltage applied to DC motor. DC motor control signal details are as
below:

Motor Control Signal 1 Port P Pin 0 / PWM0


Motor Control Signal 2 Port P Pin 1 / PWM1

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:

Servo Motor 1 Port P Pin 2 / PWM2


Servo Motor 2 Port P Pin 3 / PWM3

5) Sensor circuit design

Sensor circuit consists of 4 numbers of SFH4550 Infrared LED and 8 numbers


SFH314 NPN phototransistor. Infrared LED are driven by 15mA Constant current
source OPAMP, NPN transistor and feedback resistance. Phototransistor is used in
common emitter configuration and its collector is connected to 5 volt through 10K
Ohms Resistance. Voltage across Phototransistor is given to Analog input of Micro
controller. When more light falls on phototransistor's base, it will conduct and voltage
drop across collector and emitter of photo transistor will decrease. When less light
falls on phototransistor's base, voltage across collector and emitter of phototransistor
will increase. Analog Signal from Sensor IN0-IN7 is connected to AN0-AN7 analog
channels.

Smart car software and control

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.

2. Line tracking Method

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.

If Reading > ‘Black value’ , Reading=Black

If Reading < ‘White value’ , Reading=White

Compensated reading = (Reading - White) X Compensation ratio

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

Sensor Sensor Sensor Sensor Sensor Sensor Sensor


6 5 4 3 2 1 0
Black 236 223 250 245 250 230 240
White 15 20 16 14 16 16 16

Compensation

Ratio 1.15 1.25 1.09 1.10 1.09 1.12 1.13

Now value

Original 50 50 160 253 240 20 10


Compensated 40 37 156 254 243 4 0

Bubble sort by readings

Value 254 243 156 40 37 4 0


Sensor Sensor 3 Sensor 2 Sensor 4 Sensor 6 Sensor 5 Sensor 1 Sensor 0

3
Bubble Sort By Indices

Value 243 254 156


Sensor Sensor 2 Sensor 3 Sensor 4

Position data

Sensor 6 Sensor 5 Sensor 4 Sensor 3 Sensor 2 Sensor 1 Sensor 0


Position 3072 2560 2048 1536 1024 512 0

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

level + (Largest index sensor reading – smallest index sensor reading)

In above demonstration,

Index of middle sensor = ‘3’

ATD resolution level = 256 (8 bit)

Largest index sensor reading =156

Smallest index sensor reading =243

Therefore, position = 3*2*256 + (156-243) =1449

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.

Discrete time PID Control equation,

Outputn+1 = (Outputn +en)Ki + Kp en + Kd (en - en-1)


The first term is integral, the second proportional, and the third derivative.

Effect of inceasing PID parameters

Parameter Rise Time Overshoot Settling Time Steady state error


P Decrease Increase Small change Decrease
I Decrease Increase Increase Eliminate
D Decrease Increase Decrease Small change

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

Set PWM for


steering Servo

Set PWM for


Driving Motor

Vous aimerez peut-être aussi