PID Line Follower: Preface
PID Line Follower: Preface
Preface
PID line follower is an improved version of PD line follower. This line follower
has another component which contributes to guiding influence – the integral
one. This component takes into account e – e_old values on several iterations
(five in our case), which allows robot to even out on the line better. There are
two types of PID represented in this file – PID for three sensors with line losing
protection and PID for four sensors.
Calibration
Before using any kind of those PIDs the sensors need to be calibrated, which
means their diapason of values needs to be from 0 to 100. This is how it is done:
we remember sensor’s minimum and maximum values – on black and on white
values respectively:
PID_3:
PID_4:
PID formula
PID is based on this formula: U = KP * e + KD * (e – e_old) + KI * sum
“U” is a so-called “guiding influence”. This is a correction to motors’ speed.
“sum” is the sum of e - e_old values on five iterations.
“KP”, “KD”, “KI” – some coefficients, they are found by selection. Usually KD =
KP * 10, KI < 1.
Now let’s see how “e” is counted.
100∗d1+200∗d2+300∗d3
e = 200 − in three sensors case;
d1+d2+d3
100∗d1+200∗d2+300∗d3+400∗d4
e = 250 − in four sensors case;
d1+d2+d3+d4
There is a special block PID in both PID_3 and PID_4 projects where the “sum”
and “U” are formed:
Ports
In three sensors case the forth sensor is removed and the remaining sensors
are centered.
It is important to mention that in four sensor case there must be a gap between
2nd and 3rd sensors. But in three sensors case all the sensors must be right up to
each other.