Skip to content
ohmplay. Electronics
laboratory

Home / Tools / PID simulator

Experiment 007 / Robotics and control

PID simulator

Adjust P, I and D and observe a first-order process with output limits, sampling and anti-windup.

Workbench / Explicit model ● In your browser
01 / Adjust the model

Sliders with a wide range use a logarithmic scale. When zero is allowed, it has its own position. Type a number to set an exact value.

—
1/s
s
arb. units
Plant, sampling and limits
—
s
s
s
s
arb. units
arb. units
Try an example

02 / Plant response

Solid line: output y. Dashed line: reference r. Both use arbitrary units. Use the marker or click the graph.

s
Time 0 s
Output y 0
Error r − y 1
Applied control output 2
P contribution 2
I contribution 0
D contribution 0
Final error —
Time in saturation —

The plant starts at rest: y(0) = 0, with zero initial integral. Control output u is held constant between samples.

Control output applied to the process

Model: τ dy/dt + y = K u. Animation covers the simulation in 8 seconds of screen time and can be paused.

Use it in your classroom

Share this exercise with its current values. The link contains only numbers and model options; do not add names or email addresses.

The code includes a text link to the full explanation outside the frame. Animation starts paused. Adjust the iframe height if your platform needs it.

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

Plant: τ dy/dt + y = K u
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.