Engineering · Simulator 091
A controller pushes a mass on a spring to a target position. Tune the three PID gains, then knock the system with a disturbance or limit how hard the motor can push. Watch how each gain changes the response, and find settings that are fast, stable and accurate.
The plant is a mass on a spring with friction: m x'' + c x' + k x = u + d with m = c = k = 1. The controller measures the position x, compares it with the setpoint r, and sets the force
u = K_p e + K_i ∫e dt − K_d dx/dt, e = r − x
Proportional action pushes harder the further away the mass is. Alone it leaves a steady-state error, because the spring needs a constant force to hold the mass away from its rest point: with a P controller the mass settles at K_p / (k + K_p) of the target. Higher K_p shrinks the error but makes the response more oscillatory.
Integral action accumulates past error and keeps pushing until the error is zero, removing steady-state error, at the cost of more overshoot. Derivative action opposes motion, adding damping. Here it acts on the measured velocity rather than the error, so a sudden setpoint change does not cause a "derivative kick".
Real actuators have limits. When the force saturates, the integral keeps growing (windup) and causes extra overshoot; anti-windup stops integrating while the output is saturated.
Linear plant, continuous control simulated with 1 ms steps, ideal sensor apart from the optional noise (which is smoothed by a 5 ms filter). Overshoot is measured relative to the final value; settling uses a ±2% band. The disturbance force is applied at t = 10 s.
With P control only on this plant (k = 1), what gain K_p keeps the steady-state error below 2%? What happens to the oscillation as you raise K_p that far?
The error is k / (k + K_p) = 1 / (1 + K_p) < 0.02, so K_p > 49. The natural frequency √(1 + K_p) rises to about 7 rad/s while the damping c = 1 stays the same, so the damping ratio falls to about 0.07 and the response rings for many cycles with about 80% overshoot. That is why integral action, not a huge K_p, is used to remove steady-state error.