7.c. Advanced Line Following with 3pi: PID Control
A more advanced line following program for the 3pi is available in the folder
examples\atmegaxx8\3pi-
linefollower-pid
.
Note:
An Arduino-compatible version of this sample program can be downloaded as part
of the
[https://www.pololu.com/docs/0J17]
(see
The technique used in this example program, known as PID control, addresses some of the problems
that you might have noticed with the previous example, and it should allow you to greatly increase your
robot’s line following speed. Most importantly, PID control uses continuous functions to compute the
motor speeds, so that the jerkiness of the previous example can be replaced by a smooth response.
PID stands for Proportional, Integral, Derivative; these are the three input values used in a simple
formula to compute the speed that your robot should turn left or right.
• The
proportional
value is approximately proportional to your robot’s position with respect
to the line. That is, if your robot is precisely centered on the line, we expect a proportional
value of exactly 0. If it is to the left of the line, the proportional term will be a positive number,
and to the right of the line, it will be negative. This is computed from the result returned by
read_line()
simply by subtracting 2000.
• The
integral
value records the history of your robot’s motion: it is a sum of all of the values
of the proportional term that were recorded since the robot started running.
• The
derivative
is the rate of change of the proportional value. We compute it in this example
as the difference of the last two proportional values.
Here is the section of code that computes the PID input values:
Note that we cast the variable
position
to an
int
type in the formula for proportional. An
unsigned
int
can only store positive values, so the expression
position-2000
, without casting, would lead to a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Get the position of the line.
Note that we *must* provide
// the "sensors" argument to read_line() here, even though we
// are not interested in the individual sensor readings.
unsigned
int
position = read_line(sensors,IR_EMITTERS_ON);
// The "proportional" term should be 0 when we are on the line.
int
proportional = ((
int
)position) - 2000;
// Compute the derivative (change) and integral (sum) of the
// position.
int
derivative = proportional - last_proportional;
in= proportional;
// Remember the last position.
last_proportional = proportional;
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
7. Example Project #1: Line Following
Page 35 of 85
Содержание 0J5840
Страница 24: ...Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 5 How Your 3pi Works Page 24 of 85...
Страница 67: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 67 of 85...
Страница 77: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 77 of 85...