Why proportional control can fall short
Choose “P only”: Kp = 1, Ki = Kd = 0, K = 1, τ = 1 s and setpoint r = 1. At steady state, the plant satisfies y = u and the controller u = 1 − y. Therefore, y = 0.5 and error is 0.5. This is not a numerical error: the controller needs that error to maintain a nonzero control output.
The PI example accumulates error while it persists and can reach the setpoint if actuator limits allow. No gain is universally “best”: it depends on the process, sampling rate and actuator capability.
The model actually being simulated
e[k] = r − y[k]
u free[k] = Kp e[k] + I[k] − Kd v[k]
u[k] = clamp(u free[k], minimum, maximum)
v[k] = v[k−1] + α ((y[k]−y[k−1])/h − v[k−1])
α = h / (Tf + h)
I[k+1] = I[k] + Ki e[k] h, unless integration is blocked
y[k+1] = e^(−h/τ) y[k] + K (1−e^(−h/τ)) u[k]
The current sample’s control output is calculated first, then the integral and plant update. The derivative acts on the measurement rather than the setpoint and uses a first-order filter. Initially y, I and v are zero. Kp and K are dimensionless; Ki is in s⁻¹; Kd and Tf are in seconds. Both y and u use normalized arbitrary units.
To end exactly at the chosen duration T, the model uses N = ceil(T / maximum step) intervals and h = T/N. Effective h appears below the graph. At most 20,000 intervals are allowed, with a maximum step no larger than τ/10.
The actuator has limits too
When the control output is already at its upper limit and the error would increase it, anti-windup freezes I. It does the equivalent at the lower limit. Integration is allowed when the error helps bring the output out of saturation. Turn it off in “Unreachable setpoint” and watch I grow even though the output cannot reach the target.
This is a first-order process without delay, noise, friction or external disturbances. Plant evolution is exact for a constant control output between samples; the controller is discrete. The response does not validate gains for a real robot. Graphs fit their own ranges and may not share a vertical scale.
Common mistakes
- Confusing control output u with measured output y.
- Assuming a larger Ki overcomes a physical actuator limit.
- Comparing responses without checking τ, h and output limits.
- Assuming a larger derivative gain always improves stability.
Try it yourself
With Kp = 2, Ki = Kd = 0 and K = 1, what value does y approach?
y = 2(1 − y), so y = 2/3. Steady-state error is 1/3.
If K = 1 and the maximum control output is 1, can y stay at 5?
No. Maximum steady-state output is K × maximum u = 1. A growing integral cannot change that limit.
Concept reference: conditional integration and saturation, MathWorks. OhmPlay’s implementation and examples use the model defined above, with no time delay.