Skip to content

Commit 6198f94

Browse files
Extend pid(9) with explanation from pic.d source
Now explain the calculation done by the pid controller and how each factor contribute to the total.
1 parent 1afc365 commit 6198f94

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

docs/man/man9/pid.9

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,146 @@ value is three. If \fBdebug\fR is set to 1 (the default is 0), some
2121
additional HAL parameters will be exported, which might be useful
2222
for tuning, but are otherwise unnecessary.
2323

24+
.P
25+
In the following description, it is assumed that we are discussing
26+
position loops. However this component can be used to implement other
27+
loops such as speed loops, torch height control, and others.
28+
29+
.P
30+
Each loop has a number of pins and parameters, whose names begin
31+
with 'pid.N.', where 'N' is the channel number. Channel numbers start
32+
at zero.
33+
.P
34+
The three most important pins are 'command', 'feedback', and 'output'.
35+
For a position loop, 'command' and 'feedback' are in position units.
36+
For a linear axis, this could be inches, mm, metres, or whatever is
37+
relevant. Likewise, for a angular axis, it could be degrees, radians,
38+
etc. The units of the 'output' pin represent the change needed to
39+
make the feedback match the command. As such, for a position
40+
loop 'Output' is a velocity, in inches/sec, mm/sec, degrees/sec, etc.
41+
.P
42+
Each loop has several other pins as well. 'error' is equal
43+
to 'command' minus 'feedback'. 'enable' is a bit that enables the
44+
loop. If 'enable' is false, all integrators are reset, and the output
45+
is forced to zero. If 'enable' is true, the loop operates normally.
46+
.P
47+
The PID gains, limits, and other 'tunable' features of the loop are
48+
implemented as parameters. These are as follows:
49+
50+
.PP
51+
\fBPgain\fR Proportional gain
52+
.PD 0
53+
.P
54+
.PD
55+
\fBIgain\fR Integral gain
56+
.PD 0
57+
.P
58+
.PD
59+
\fBDgain\fR Derivative gain
60+
.PD 0
61+
.P
62+
.PD
63+
\fBbias\fR Constant offset on output
64+
.PD 0
65+
.P
66+
.PD
67+
\fBFF0\fR \fR Zeroth order Feedforward gain
68+
.PD 0
69+
.P
70+
.PD
71+
\fBFF1\fR \fR First order Feedforward gain
72+
.PD 0
73+
.P
74+
.PD
75+
\fBFF2\fR \fR Second order Feedforward gain
76+
.PD 0
77+
.P
78+
.PD
79+
\fBFF3\fR \fR Third order Feedforward gain
80+
.PD 0
81+
.P
82+
.PD
83+
\fBdeadband\fR Amount of error that will be ignored
84+
.PD 0
85+
.P
86+
.PD
87+
\fBmaxerror\fR Limit on error
88+
.PD 0
89+
.P
90+
.PD
91+
\fBmaxerrorI\fR Limit on error integrator
92+
.PD 0
93+
.P
94+
.PD
95+
\fBmaxerrorD\fR Limit on error differentiator
96+
.PD 0
97+
.P
98+
.PD
99+
\fBmaxcmdD\fR Limit on command differentiator
100+
.PD 0
101+
.P
102+
.PD
103+
\fBmaxcmdDD\fR Limit on command 2nd derivative
104+
.PD 0
105+
.P
106+
.PD
107+
\fBmaxcmdDDD\fR Limit on command 3rd derivative
108+
.PD 0
109+
.P
110+
.PD
111+
\fBmaxoutput\fR Limit on output value
112+
.P
113+
All of the limits (max____) are implemented such that if the parameter
114+
value is zero, there is no limit.
115+
.P
116+
A number of internal values which may be useful for testing and tuning
117+
are also available as parameters. To avoid cluttering the parameter
118+
list, these are only exported if "debug=1" is specified on the insmod
119+
command line.
120+
121+
.PP
122+
\fBerrorI\fR Integral of error
123+
.PD 0
124+
.P
125+
.PD
126+
\fBerrorD\fR Derivative of error
127+
.PD 0
128+
.P
129+
.PD
130+
\fBcommandD\fR Derivative of the command
131+
.PD 0
132+
.P
133+
.PD
134+
\fBcommandDD\fR 2nd derivative of the command
135+
.PD 0
136+
.P
137+
.PD
138+
\fBcommandDDD\fR 3rd derivative of the command
139+
140+
.P
141+
The PID loop calculations are as follows (see the code in pid.c for
142+
all the nitty gritty details):
143+
.IP
144+
.nf
145+
error = command - feedback
146+
if ( abs(error) < deadband ) then error = 0
147+
limit error to +/- maxerror
148+
errorI += error * period
149+
limit errorI to +/- maxerrorI
150+
errorD = (error - previouserror) / period
151+
limit errorD to +/- maxerrorD
152+
commandD = (command - previouscommand) / period
153+
limit commandD to +/- maxcmdD
154+
commandDD = (commandD - previouscommandD) / period
155+
limit commandDD to +/- maxcmdDD
156+
commandDDD = (commandDD - previouscommandDD) / period
157+
limit commandDDD to +/- maxcmdDDD
158+
output = bias + error * Pgain + errorI * Igain +
159+
errorD * Dgain + command * FF0 + commandD * FF1 +
160+
commandDD * FF2 + commandDDD * FF3
161+
limit output to +/- maxoutput
162+
.fi
163+
24164
.SH NAMING
25165
The names for pins, parameters, and functions are prefixed as:
26166
\fBpid.N.\fR for N=0,1,...,num\-1 when using \fBnum_chan=num\fR

0 commit comments

Comments
 (0)