PID
Combines proportional, forward-Euler integral, and backward-difference derivative terms from an error input.
Behavior
Section titled “Behavior”i(0) = ici(n) = i(n-1) + dt * e(n-1) for n > 0d(n) = (e(n) - e(n-1)) / dt with e(-1) = e_icu_out(n) = kp * e(n) + ki * i(n) + kd * d(n)| Direction | Name | Type |
|---|---|---|
| Input | e |
T |
| Output | u_out |
T |
Parameters
Section titled “Parameters”| Name | Type | Default | Meaning |
|---|---|---|---|
T |
type (default f64) |
f64 |
Float scalar type |
kp, ki, kd |
T |
1.0, 0.0, 0.0 |
Proportional, integral, and derivative gains |
ic |
T |
0.0 |
Initial integral state |
e_ic |
T |
0.0 |
Error sample before the first tick |
T defaults to f64 and is a scalar float type. dt must be nonzero because the derivative term is always computed, even when kd = 0.
Example
Section titled “Example”With dt = 0.1, kp = 2, ki = 1, kd = 0, ic = e_ic = 0, and errors 1, 1, outputs are 2, 2.1.