Machinekit Documentation

HAL Component — PIDV2


All instantiable components can be loaded in two manners

Using loadrt with or without count= | names= parameters as per legacy components
Using newinst, which names the instance and allows further parameters and arguments
primarily pincount= which can set the number of pins created for that instance (where applicable)


pidv2 — HAL component that provides Proportional Integeral/Derivative control loops. It is a realtime component.




loadrt pidv2
newinst pidv2 <newinstname> [ pincount=N | iprefix=prefix ] [instanceparamX=X | argX=X ]

( args in [ ] denote possible args and parameters, may not be used in all components )


HAL component that provides Proportional/
Integeral/Derivative control loops.  It is a realtime component.
The number of pid components is set by the module parameter 'num_chan='
when the component is insmod'ed.  Alternatively, use the
names= specifier and a list of unique names separated by commas.
The names= and num_chan= specifiers are mutually exclusive.
In this documentation, 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.
Each loop has a number of pins and parameters, whose names begin
with 'pid.x.', where 'x' is the channel number.  Channel numbers
start at zero.
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 relavent.  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.
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.
The PID gains, limits, and other 'tunable' features of the
loop are implemented as parameters.  These are as follows:
Pgain	Proportional gain
Igain	Integral gain
Dgain	Derivative gain
bias	Constant offset on output
FF0		Zeroth order Feedforward gain
FF1		First order Feedforward gain
FF2		Second order Feedforward gain
deadband	Amount of error that will be ignored
maxerror	Limit on error
maxerrorI	Limit on error integrator
maxerrorD	Limit on error differentiator
maxcmdD	Limit on command differentiator
maxcmdDD	Limit on command 2nd derivative
maxoutput	Limit on output value
All of the limits (max____) are implemented such that if the
parameter value is zero, there is no limit.
A number of internal values which may be usefull 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.
errorI	Integral of error
errorD	Derivative of error
commandD	Derivative of the command
commandDD	2nd derivative of the command
The PID loop calculations are as follows (see the code for
all the nitty gritty details):
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
output = bias + error * Pgain + errorI * Igain +
         errorD * Dgain + command * FF0 + commandD * FF1 +
         commandDD * FF2
limit output to +/- maxoutput
This component exports one function called ''
for each PID loop.  This allows loops to be included in different
threads and execute at different rates.

FUNCTIONS ( OR <newinstname>.do-pid-calcs.funct (requires a floating-point thread) )



John Kasunich


GPL v2