Control¶
- class pathsim.blocks.ctrl.PID(Kp=0, Ki=0, Kd=0, f_max=100)[source]¶
Bases:
BlockProportional-Integral-Differntiation (PID) controller.
The transfer function is defined as
\[H_\mathrm{diff}(s) = K_p + K_i \frac{1}{s} + K_d \frac{s}{1 + s / f_\mathrm{max}}\]where the differentiation is approximated by a high pass filter that holds for signals up to a frequency of approximately f_max.
Note
Depending on f_max, the resulting system might become stiff or ill conditioned! As a practical choice set f_max to 3x the highest expected signal frequency. Since this block uses an approximation of real differentiation, the approximation will not hold if there are high frequency components present in the signal. For example if you have discontinuities such as steps or square waves.
Example
The block is initialized like this:
#cutoff at 1kHz pid = PID(Kp=2, Ki=0.5, Kd=0.1, f_max=1e3)
- Parameters:
- op_dyn¶
internal dynamic operator for ODE component
- Type:
- op_alg¶
internal algebraic operator
- Type:
- update(t)[source]¶
update system equation fixed point loop, with convergence control
- Parameters:
t (float) – evaluation time
- class pathsim.blocks.ctrl.AntiWindupPID(Kp=0, Ki=0, Kd=0, f_max=100, Ks=10, limits=[-10, 10])[source]¶
Bases:
PIDProportional-Integral-Differntiation (PID) controller with tracking anti-windup mechanism (back-calculation).
Anti-windup mechanisms are needed when the magnitude of the control signal from the PID controller is limited by some real world saturation. In these cases, the integrator will continue to acumulate the control error and “wind itself up”. Once the setpoint is reached, this can result in significant overshoots. This implementation adds a conditional feedback term to the internal integrator that “unwinds” it when the PID output crosses some limits. This is pretty much a deadzone feedback element for the integrator.
Mathematically, this block implements the following set of ODEs
\[\begin{split}\begin{eqnarray} \dot{x}_1 =& f_\mathrm{max} (u - x_1) \\ \dot{x}_2 =& u - w \\ \end{eqnarray}\end{split}\]with the anti-windup feedback (depending on the pid output)
\[w = K_s (y - \min(\max(y, y_\mathrm{min}), y_\mathrm{max}))\]and the output itself
\[y = K_p u - K_d f_\mathrm{max} x_1 + K_i x_2\]Note
Depending on f_max, the resulting system might become stiff or ill conditioned! As a practical choice set f_max to 3x the highest expected signal frequency. Since this block uses an approximation of real differentiation, the approximation will not hold if there are high frequency components present in the signal. For example if you have discontinuities such as steps or squere waves.
Example
The block is initialized like this:
#cutoff at 1kHz, windup limits at [-5, 5] pid = AntiWindupPID(Kp=2, Ki=0.5, Kd=0.1, f_max=1e3, limits=[-5, 5])
- Parameters:
Kp (float) – poroportional controller coefficient
Ki (float) – integral controller coefficient
Kd (float) – differentiator controller coefficient
f_max (float) – highest expected signal frequency
Ks (float) – feedback term for back calculation for anti-windup control of integrator
limits (array_like[float]) – lower and upper limit for PID output that triggers anti-windup of integrator
- op_dyn¶
internal dynamic operator for ODE component
- Type:
- op_alg¶
internal algebraic operator
- Type: