negative overflow. In this particular case, it actually wouldn’t affect the results, but it is always a good
idea to use casting to avoid unexpected behavior.
Each of these input values provides a different kind of information. The next step is a simple formula
that combines all of the values into one variable, which is then used to determine the motor speeds:
The values 1/20, 1/10000, and 3/2 represent
adjustable
parameters that determine how your 3pi will
react to the line. The particular values chosen for this example were somewhat arbitrarily picked,
and while they work sufficiently for typical line following, there is plenty of room to improve them.
In general, increasing these PID parameters will make
power_difference
larger, causing stronger
reactions, while decreasing them will make the reactions weaker. It’s up to you to think about the
different values and experiment with your robot to determine what effect each parameter has. This
example gives the motors a maximum speed of 100, which is a safe initial value. Once you have
adjusted the parameters to work well at a speed of 100, try increasing the speed. You’ll probably need
to readjust the parameters as the maximum speed increases. By gradually increasing the maximum
speed and tuning the parameters, see if you can get your 3pi to run as fast as possible! We have been
able to run 3pis with a maximum speed of 255 on courses with 6"-radius curves, all by finding the right
PID parameters.
Please see
of the
[https://www.pololu.com/docs/0J32]
gallery for videos of 3pi
line followers using tuned PID and higher maximum speeds.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Compute the difference between the two motor power settings,
// m1 - m2.
If this is a positive number the robot will turn
// to the right.
If it is a negative number, the robot will
// turn to the left, and the magnitude of the number determines
// the sharpness of the turn.
int
power_difference = proportional/20 + integral/10000 + derivative*3/2;
// Compute the actual motor settings.
We never set either motor
// to a negative value.
const
int
max = 60;
if
(power_difference > max)
power_difference = max;
if
(power_difference < -max)
power_difference = -max;
if
(power_difference < 0)
set_motors(max+power_difference, max);
else
set_motors(max, max-power_difference);
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
7. Example Project #1: Line Following
Page 36 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...