This library contains a PID controller with additional feed forward.
The PID controller has the following features:
- Addition of optional feed forward component. The PID calculation pseudocode is:
output = kp*error + ki*errorIntegral + kd*errorDerivative + kf*setpoint
Settingkf
to zero gives a traditional PID controller. - Calculation of derivative on measurement, avoiding "derivative kick" when the setpoint changes.
- Two forms of the update function
update
andupdateDelta
with ameasurementDelta
parameter. Providing this parameter allows filteringmeasurementDelta
before the PID calculation. - delta-t input parameter to PID
update
function. This allows for jitter in the timing of the call to theupdate
function. - A choice of two methods of controlling integral windup. Either the integral term can be limited to a maximum value, or it can be set to zero when the output saturates. Both methods can be used together, if desired.
- Ability to switch integration off. Useful, for example, for a vehicle that has its motors turned on, but has not yet started moving.
- Functions to return the current error terms. These can be used for PID tuning, telemetry, and test code.
The PID controller deliberately does not implement these features:
- Output clipping. Usually it is desirable to clip the PID output before it is fed to the device being controlled. However often several PID outputs are combined, when this is the case it is the combined output that needs to be clipped.
- PID "negation". Some PID controllers provide a function to negate all the PID constants. If this is required, just subtract the PID output, rather than add it.
- Option to calculate derivative on input. This can be achieved by calculating
inputDelta
rather thanmeasurementDelta
and using it as input to theupdateDelta
function. Note this value must be negated, ieupdateDelta(measurement, -inputDelta, deltaT)
should be called. - Filtering of the D-term. Providing a D-term filter limits flexibility - the user no choice in the type of filter used.
Instead the
updateDelta
function can be used, withmeasurementDelta
filtered by a filter provided by the user.