One or more PID (proportional-integral-differential) controllers. Each controller is specified by a different index: 1, 2, 3, ...
PID controllers are used to control a system using feedback: measure an error and use this to apply a correction. A common use case is operating an actuator with an encoder, such as a robot wheel, to move a specified amount. For an actuator, you can determine the error by comparing where you want to be with where the encoder says you are. Feed the measured error into compute pid and scale the resulting correction to determine a drive signal. See Recommendations for using the PID library for more information.
For each block, there is a short description entry and a detailed block and component description. You can click on block pictures in the short description table to access the details.
Compute the next PID correction for the specified PID loop. The inputs are as follows:
index
: index of the PID loop: 1, 2, 3, ...error
: error to correctpCoeff
: proportional coefficient (corr/error)iCoeff
: integral coefficient (corr=msec/error)dCoeff
: derivitive coefficient (corr/error-msec)maxIntegral
: maximum absolute value of the integrated error; ignored if 0
Reset the specified PID loop. It may be useful to reset a PID before commanding a new move.
Limit the range of a value. This is provided to constrain the drive signal to useful values. The algorithm is as follows (where |value|
means the absolute value of value
):
|value| < deadband
: return 0.|value| < minimum
: return minimum
with the sign of value
.|value| > maximum
: return maximum
with the sign of value
.
Apply the sign of the first argument to the second argument:
pCoeff
significantly larger than 1 (e.g. 100 or 1000),pid_constrainValue
.iCoeff
can easily lead to oscillations or instability.dCoeff
(this is very common when specifying a non-zero iCoeff
).maxIntegral
.