compute¶
- PIDController.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).