PIDController¶
- class PIDController(Kp: float | int, Ki: float | int, Kd: float | int, clamping: bool = False, reference_min: float | int | None = None, reference_max: float | int | None = None)¶
Bases:
objectAdded in version 1.3.0.
PIDControllerobject.Proportional-integral-derivative controller which computes the reference value, used to keep a variable under control with respect to a set value, based on current value and control parameters.
Methods¶
compute()It computes the reference value based on current error.
reset()It resets the stored cumulative error integral, used for integrative part, and the previous error, used for derivative part.
Raises
- compute(error: float | int, time_step: TimeInterval) float | int¶
It computes the reference value based on current error.
Parameters¶
Returns¶
Notes
The reference value is computed as:
\[u(t) = K_P e(t) + K_I \int_0^t e(\tau) d \tau + K_D \frac{d e(t)}{d t}\]where:
\(u(t)\) is the reference value,
\(e(t)\) is the current
error,\(K_P\) is the proportional constant
Kp,\(K_I\) is the integral constant
Ki,\(K_D\) is the derivative constant
Kd.
The integral part is approximated with:
\[\int_0^t e(\tau) d \tau \approx \frac{1}{2}(e_i + e_{i - 1}) dt\]and the derivative part is approximated with:
\[\frac{d e(t)}{d t} \approx \frac{e_i - e_{i - 1}}{dt}\]where:
\(e_i\) is the current
error,\(e_{i - 1}\) is the error at the previous time step,
\(dt\) is the
time_step.
If the reference value \(u(t)\) exceeds the limits
reference_minorreference_max, then it is saturated to these values. In this case, ifclampingisTrue, then the cumulative error is not updated (anti-windup).