compute

PIDController.compute(error: float | int, time_step: TimeInterval) float | int

It computes the reference value based on current error.

Parameters

errorfloat or int

Current error.

time_stepTime

Time interval to be used for integrative and derivative parts.

Returns

float or int

Reference value to be used for control.

Raises

TypeError
  • If error is not a float or an int,

  • if time_step is not an instance of Time.

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_min or reference_max, then it is saturated to these values. In this case, if clamping is True, then the cumulative error is not updated (anti-windup).