Machinekit Documentation

HAL Component — AT_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)


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




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

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


 This file, 'at_pid.icomp', is a HAL component that provides Proportional/
Integeral/Derivative control loops.  It is a realtime component.
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.
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
cmdD     Derivative of the command
cmdDd    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 ( fabs(error) < deadband ) then error = 0
limit error to +/- maxerror
errorI += error * period
limit errorI to +/- maxerrorI
errorD = (error - previouserror) / period
limit errorD to +/- paxerrorD
cmdD = (command - previouscommand) / period
limit cmdD to +/- maxcmdD
cmdDd = (cmdD - previouscmdD) / period
limit cmdDd to +/- maxcmdDD
output = bias + error * Pgain + errorI * Igain +
         errorD * Dgain + command * FF0 + cmdD * FF1 +
         cmdDd * FF2
limit output to +/- maxoutput
This component exports one function called '<name>.do-pid-calcs'

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



John Kasunich


GPL v2