Skip to content

PID

Combines proportional, forward-Euler integral, and backward-difference derivative terms from an error input.

i(0) = ic
i(n) = i(n-1) + dt * e(n-1) for n > 0
d(n) = (e(n) - e(n-1)) / dt with e(-1) = e_ic
u_out(n) = kp * e(n) + ki * i(n) + kd * d(n)
Direction Name Type
Input e T
Output u_out T
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.

With dt = 0.1, kp = 2, ki = 1, kd = 0, ic = e_ic = 0, and errors 1, 1, outputs are 2, 2.1.