Control¶
PID Controller¶
control.pid · Control
Continuous PID controller (parallel form) with a filtered derivative:

The input is the control error e. The output is limited to [lower, upper]. When the output saturates, the integral term keeps growing ("winds up") and causes overshoot. anti_windup prevents that:
clampingstops integrating while the output is saturated and the error would push it further out.back_calculationfeeds the excessKb·(y - u_unsat)back into the integrator. It is smooth, which variable-step solvers handle well.

With variable-step solvers, zero-crossing detection locates the moments the output saturates exactly. With
clamping, the integrator then slides along the limit: it integrates just enough to keep the output there
(a thin boundary layer of 0.1 % of the limit, instead of switching the integrator on and off, which would
chatter). With a fixed-step solver the integrator is switched off in every step that would push the output
further out.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
P |
1.0 |
Proportional gain | |
I |
0.0 |
1/s | Integral gain |
D |
0.0 |
s | Derivative gain |
N |
100.0 |
rad/s | Derivative filter coefficient |
initial_integrator |
0.0 |
Initial value of the integral term | |
upper |
inf | Output upper limit | |
lower |
-inf | Output lower limit | |
anti_windup |
'none' |
Anti-windup method used while the output is saturated — one of none, clamping, back_calculation |
|
Kb |
1.0 |
1/s | Back-calculation gain |
Direct feedthrough: yes
Discrete PID Controller¶
control.discrete_pid · Control
Discrete PID controller (parallel form), as it would run on an ECU every sample_time seconds.
The integral and the derivative filter use forward Euler:
The derivative filter is stable only when N·T < 2. See PID for the anti-windup options;
clamping works well here because the controller is discrete.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
P |
1.0 |
Proportional gain | |
I |
0.0 |
1/s | Integral gain |
D |
0.0 |
s | Derivative gain |
N |
100.0 |
rad/s | Derivative filter coefficient |
initial_integrator |
0.0 |
Initial value of the integral term | |
upper |
inf | Output upper limit | |
lower |
-inf | Output lower limit | |
anti_windup |
'none' |
Anti-windup method used while the output is saturated — one of none, clamping, back_calculation |
|
Kb |
1.0 |
1/s | Back-calculation gain |
sample_time |
0.01 |
s | Sample period |
Direct feedthrough: yes