Discrete PID controller
control.discrete_pid
PID control of the error input, computed every Ts seconds and held between samples. At each sample the integral adds ki Ts times the error (backward Euler), and the derivative is kd times the change in error since the last sample over Ts. The first sample is at t = Ts; before it the output is 0.
Ports
| Name | Domain | Direction |
|---|---|---|
u | signal | in |
y | signal | out |
Parameters
| Name | Unit | Default | Range | Description |
|---|---|---|---|---|
kp | 1 | 1 | Proportional gain | |
ki | 1/s | 1 | Integral gain | |
kd | s | 0 | Derivative gain | |
Ts | s | 0.01 | 1e-9 to ∞ | Sample period |
Variables
| Name | Unit | Start | Description |
|---|---|---|---|
I | 1 | Integral term | |
ep | 1 | Error at the last sample | |
yh | 1 | Held output | |
next | s | Ts | Time of the next sample |
Equations
der(I) = 0 der(ep) = 0 der(yh) = 0 der(next) = 0 when time >= next then reinit(I, I + ki * Ts * u), reinit(ep, u), reinit(yh, kp * u + I + ki * Ts * u + kd * (u - ep) / Ts), reinit(next, next + Ts) y = yh