Skip to content

Commit

Permalink
Extend pid(9) with explanation from pic.d source
Browse files Browse the repository at this point in the history
Now explain the calculation done by the pid controller and how
each factor contribute to the total.
  • Loading branch information
petterreinholdtsen committed Jul 5, 2022
1 parent 2e60f9e commit 00dc03b
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions docs/man/man9/pid.9
Expand Up @@ -21,6 +21,146 @@ value is three. If \fBdebug\fR is set to 1 (the default is 0), some
additional HAL parameters will be exported, which might be useful
for tuning, but are otherwise unnecessary.

.P
In the following description, it is assumed that we are discussing
position loops. However this component can be used to implement other
loops such as speed loops, torch height control, and others.

.P
Each loop has a number of pins and parameters, whose names begin
with 'pid.N.', where 'N' is the channel number. Channel numbers start
at zero.
.P
The three most important pins are 'command', 'feedback', and 'output'.
For a position loop, 'command' and 'feedback' are in position units.
For a linear axis, this could be inches, mm, metres, or whatever is
relevant. Likewise, for a angular axis, it could be degrees, radians,
etc. The units of the 'output' pin represent the change needed to
make the feedback match the command. As such, for a position
loop 'Output' is a velocity, in inches/sec, mm/sec, degrees/sec, etc.
.P
Each loop has several other pins as well. 'error' is equal
to 'command' minus 'feedback'. 'enable' is a bit that enables the
loop. If 'enable' is false, all integrators are reset, and the output
is forced to zero. If 'enable' is true, the loop operates normally.
.P
The PID gains, limits, and other 'tunable' features of the loop are
implemented as parameters. These are as follows:

.PP
\fBPgain\fR Proportional gain
.PD 0
.P
.PD
\fBIgain\fR Integral gain
.PD 0
.P
.PD
\fBDgain\fR Derivative gain
.PD 0
.P
.PD
\fBbias\fR Constant offset on output
.PD 0
.P
.PD
\fBFF0\fR \fR Zeroth order Feedforward gain
.PD 0
.P
.PD
\fBFF1\fR \fR First order Feedforward gain
.PD 0
.P
.PD
\fBFF2\fR \fR Second order Feedforward gain
.PD 0
.P
.PD
\fBFF3\fR \fR Third order Feedforward gain
.PD 0
.P
.PD
\fBdeadband\fR Amount of error that will be ignored
.PD 0
.P
.PD
\fBmaxerror\fR Limit on error
.PD 0
.P
.PD
\fBmaxerrorI\fR Limit on error integrator
.PD 0
.P
.PD
\fBmaxerrorD\fR Limit on error differentiator
.PD 0
.P
.PD
\fBmaxcmdD\fR Limit on command differentiator
.PD 0
.P
.PD
\fBmaxcmdDD\fR Limit on command 2nd derivative
.PD 0
.P
.PD
\fBmaxcmdDDD\fR Limit on command 3rd derivative
.PD 0
.P
.PD
\fBmaxoutput\fR Limit on output value
.P
All of the limits (max____) are implemented such that if the parameter
value is zero, there is no limit.
.P
A number of internal values which may be useful for testing and tuning
are also available as parameters. To avoid cluttering the parameter
list, these are only exported if "debug=1" is specified on the insmod
command line.

.PP
\fBerrorI\fR Integral of error
.PD 0
.P
.PD
\fBerrorD\fR Derivative of error
.PD 0
.P
.PD
\fBcommandD\fR Derivative of the command
.PD 0
.P
.PD
\fBcommandDD\fR 2nd derivative of the command
.PD 0
.P
.PD
\fBcommandDDD\fR 3rd derivative of the command

.P
The PID loop calculations are as follows (see the code in pid.c for
all the nitty gritty details):
.IP
.nf
error = command - feedback
if ( abs(error) < deadband ) then error = 0
limit error to +/- maxerror
errorI += error * period
limit errorI to +/- maxerrorI
errorD = (error - previouserror) / period
limit errorD to +/- maxerrorD
commandD = (command - previouscommand) / period
limit commandD to +/- maxcmdD
commandDD = (commandD - previouscommandD) / period
limit commandDD to +/- maxcmdDD
commandDDD = (commandDD - previouscommandDD) / period
limit commandDDD to +/- maxcmdDDD
output = bias + error * Pgain + errorI * Igain +
errorD * Dgain + command * FF0 + commandD * FF1 +
commandDD * FF2 + commandDDD * FF3
limit output to +/- maxoutput
.fi

.SH NAMING
The names for pins, parameters, and functions are prefixed as:
\fBpid.N.\fR for N=0,1,...,num\-1 when using \fBnum_chan=num\fR
Expand Down

0 comments on commit 00dc03b

Please sign in to comment.