PID Controller for Rust

A proportional-integral-derivative (PID) controller.
Features
- Visibility into individual contribution of P, I, and D terms which often need to be logged for later analysis and parameter tuning.
- Output limits on a per term basis.
- Mitigation of integral windup using integral term limit.
- Mitigation of derivative kick by using the derivative of the measurement rather than the derivative of the error.
- On-the-fly changes to
setpoint/kp/ki/kd.- Mitigation of output jumps when changing
kiby storing the integration ofe(t) * ki(t)rather than onlye(t).
- Mitigation of output jumps when changing
- Generic float type parameter to support
f32orf64. - Support for
no_stdenvironments, such as embedded systems.
Example
extern crate pid;
use Pid;
Assumptions
- Measurements occur at equal spacing. (
t(i) = t(i-1) + C) - Output limits per term are symmetric around 0 (
-limit <= term <= limit).
Formulation
There are several different formulations of PID controllers. This library uses the independent form:
where:
- C(t) = control output, the output to the actuator.
- P(t) = process variable, the measured value.
- e(t) = error = S(t) - P(t)
- S(t) = set point, the desired target for the process variable.
kp/ki/kd can be changed during operation and can therefore also be a
function of time.
If you're interested in the dependent form, add your own logic that computes
kp/ki/kd using dead time, time constant, kc, or whatever else.
Todo
- Three-term output limit:
MAX(p + i + d, global_limit). - Helper for (auto-)tuning by detecting frequency & amplitude of oscillations.