You are on page 1of 11

Positional Control of Vehicle with IR Range Sensor

Completed by:
Michael Claassen
Sam Walters
Fall Semester 2016
MECA 482 Control System Design
Instructor: Dr. Varahamurti
California State University, Chico

Introduction
The goal of the project is to construct a control system using a PID controller. By
altering the parameters in the PID controller we can observe different system
responses to various types of inputs. For this project, the feedback will be read
by a microcontroller from an infrared proximity sensor. The PID controller will
then calculate a value based on this input, and give an output value, which will
be used to control motor speeds on a vehicle. Input will be a distance in
centimeters that the vehicle must keep from an object in front of it. Step, ramp,
and impulse inputs will be tested.

Necessary Equipment

Arduino Uno
Sharp GP2Y0A21YK0F IR Proximity Sensor
2 Parallax Continuous Rotation Servo Motors
Parallax BoeBot Robot Development Kit
Miscellaneous wires and connectors
6V DC Power supply (4 AA Batteries)

Figure 1: Wiring Diagram

System Overview
The system hardware is primarily Parallaxs BoeBot Robot platform. It consists of a
small car frame with two continuous rotation servos attached to the left and right
wheels respectively. Rotation of these motors causes the wheels to spin and the car
to move. The controller being used is an Arduino Uno R3. This board was selected
for its availability and ease of use. Two digital outputs are used to control the motors
using a PWM signal. An analog input is used to read data from the IR proximity
sensor. Some calculation is required to turn this analog signal into a human
readable number that represents distance. A PID controller was implemented in the
Arduino language which is very similar to C. After being given a setpoint, the PID
controller calculates the error between the set point and the input from the IR
sensor. Based on this error and the P, I, and D gain values, an output is calculated.
This output is then scaled accordingly to provide proper output values to the
motors. The system will operate until the error is zero. This process can be summed
up below.
1.
2.
3.
4.
5.
6.

BoeBot is set far away from wall


Setpoint is given
Proximity data is read
PID values are calculated based on error
PID output speeds to motors
Repeat from part 3

Conceptual Block Diagram of PID Controller


P

Kp

Set point
distance

I
+
-

Ki

e (t )
D

Kd

de(t )
dt
Infrared
signal

Figure 2: PID Block Diagram

+
+

Output
to
motors

Test Procedure
Data Collection: Beobot is placed touching the wall with the infrared sensor facing
the wall. The initial distance is 0 cm. The Arduino mounted on the boebot is
connected to the computer. The Arduino program is opened and the type of control
system (P,PD, PID, etc.) is chosen. The Arduino reset button is pressed. The boebot
is begins to move backward toward the setpoint distance. The Arduino code records
the distance data and sample number and outputs that information via USB to the
Arduino Serial Monitor. Data is recorded every 10 milliseconds. Unneeded data
collected after procedure is finished is deleted. Data is checked for reasonable
results. The data is save as a text file (.txt) and exported to excel.
Data Reduction: A scatterplot is made of the imported data and the general shape
is compared to expected shape. Maximum output, peak time, and settling time is
determined from scatterplot. These parameters are checked to determine if they
meet minimum requirements given by the instructor. Percent overshoot, dampening
ratio, and natural frequency are calculated and recorded. A Matlab program then
takes these values and computes the transfer function of the system, a transient
response plot, and corresponding Bode plots (gain and phase shift). These results
are then compared to results taken from hand calculations. Table 1 below outlines
some of the highlights from each test. Complete test results, Matlab analysis, and
hand calculations are all included in the back of this report.
Table 1: Data and calculation results

Inp
ut

Max
Output(cm)

Tp
(ms)

Ts
(ms)

%OS

Ess (%)

n(Hz)

21.45

136

164

6.92
9

0.30

0.647
5

37.67

21.09

131

393

3.84
0

1.55

0.720
0

14.14

23.82

134

290*

15.9
51

2.71

0.504
5

27.34

21.45

123

243

6.92
9

0.30

0.647
5

25.42

PD

PI

PID

*time of steady state was taken when oscillation became uniform

Conclusion
This project highlights the usefulness of a close loop control system. Using the
feedback from the sensor, we can monitor a system response and correct
accordingly. If the response is not desirable, a PID controller can be implemented
giving the user better control over the response by altering the gain (Kp, Ki, Kd)
values. The project was a very beneficial educational experience and put theory
to the test. A software PID controller can be built without much difficulty or
programming experience, although some programming knowledge is helpful.
Charts
I) P Control

P Control Position vs. Time

284.6
s 4.878s14.19
2

TF=

II) PD Control

PD Control Time vs. Position

40.58
s 2.036s1.998
2

TF=

III) PI Control

PI Control Position vs. Time

153.6
s 2.759s 7.475
2

TF=

IV) PID Control

PID Control Position vs. Time


25
20
15
Position (cm)
10
5
0

129.6
s 3.292s 6.463
2

TF=

Extra Credit
The system response was recorded with a ramp input and that data is shown below.
A good example of how expected data should look can be seen from approximately
50ms to 250ms. We can see the system closely following a steadily increasing set
point. This was done by setting the set point to 10cm and then increasing the value
of the set point by 0.05cm every time the PID loop was executed. We can get an
idea of how accurately the response to the ramp input is by finding a best fit line.
We can see the equation of the linear trend line is quite similar to the equation
being used for the input. The trend line has an offset of approximately 10 and a
slope close to 0.05. If a trend line were take only for data points between 50-250ms
we are confident that the equation of that line would be even closer to the expected
values.

PID Ramp Input vs. Time


f(x) = 0.04x + 9.65

50

100

150

200

250

300

350

400

450

Time (centiseconds)

In order to produce an impulse input that would pull the system back down after the
impulse, the set point was set at a higher value for a short period of time, and then
set to the to a lower value. In the figure below we can see it the low point is 10cm
and the high point is 20cm. We can see the system clearly responded to the impulse
at around 400ms. Although the set point of the impulse was 20cm, we can see the
PID controller briefly over shot the set point. This could probably be minimized by
reducing the Ki gain value, but no tests have been conducted to confirm this.

PID Impulse Time vs. Distance

You might also like