PIDController#
- class do_dpc.control_utils.pid.PIDController(gains, dt, alpha=0.1)[source]#
Bases:
objectA discrete-time PID controller. This class implements a discrete-time PID (Proportional-Integral-Derivative) controller. It computes the control action based on the error between the desired setpoint and the current process variable, using the PID control law:
\[u(t) = K_p e(t) + K_i \int_0^t e(\tau) d\tau + K_d \frac{d}{dt} e(t)\]- where:
\(u(t)\) is the control output
\(e(t)\) is the error between the setpoint and the process variable
\(K_p\), \(K_i\), and \(K_d\) are the proportional, integral, and derivative gains, respectively.
- dt#
Sampling time (time step between updates).
- Type:
float
- alpha#
Smoothing factor for the derivative term (low-pass filter for noise reduction).
- Type:
float
- integral#
The accumulated integral term.
- Type:
float
- prev_error#
The previous error used for the derivative calculation.
- Type:
float
- filtered_derivative#
The filtered derivative term.
- Type:
float
- Parameters:
gains (PIDGains) – An instance of PIDGains containing Kp, Ki, and Kd.
dt (float) – Sampling time.
alpha (float, optional) – Smoothing factor for the derivative term. Defaults to 0.1.
- Raises:
ValueError – If dt is not positive.
Methods#
compute#
- do_dpc.control_utils.pid.PIDController.compute(self, error)#
Computes the discrete PID control output.
- Parameters:
error (float) – The error signal (difference between setpoint and measurement).
- Returns:
The computed control signal.
- Return type:
float
compute_with_derivative#
- do_dpc.control_utils.pid.PIDController.compute_with_derivative(self, error, error_derivative)#
Computes the discrete PID control output with an externally provided error derivative.
- Parameters:
error (float) – The error signal (difference between setpoint and measurement).
error_derivative (float) – The derivative of the error signal.
- Returns:
The computed control signal.
- Return type:
float