PID Tuning and Step Response
A practical PID workflow based on measured step response, saturation behavior, and repeatable tuning records.
A PID controller is only as good as the plant model, measurement path, actuator limits, and test record around it. Tuning by feel can work on a bench. It does not leave evidence that another engineer can reproduce.
Define the loop
Write the loop down before tuning:
- controlled variable,
- setpoint source,
- sensor sample rate and filtering,
- actuator command range,
- update period,
- sign convention,
- saturation limits,
- safe stop behavior.
The controller output usually looks like:
[u(t) = K_p e(t) + K_i \int e(t)\,dt + K_d \frac{de(t)}{dt}]
where $e(t)$ is the setpoint minus measurement. The formula is not the design. The design is how this runs with sampled data, noise, latency, and actuator limits.
Capture an open-loop step first
Before closing the loop, command a safe actuator step and record the response. Measure:
- dead time,
- rise time,
- steady-state gain,
- overshoot,
- settling time,
- noise amplitude,
- actuator current or thermal behavior when relevant.
For a motor, a useful record includes command, encoder or IMU response, supply voltage, current limit, sample rate, and load condition. Repeat the same step several times. If the plant response is not repeatable, PID tuning will hide the real problem.
Start with proportional control
Set $K_i = 0$ and $K_d = 0$. Increase $K_p$ until the response is fast enough or starts to ring. Back off before adding integral. Proportional control proves sign, scale, and timing. If a small positive setpoint drives the output farther from the target, stop and fix the sign.
Good proportional evidence:
- response moves in the correct direction,
- output does not saturate immediately,
- oscillation threshold is known,
- steady-state error is measured.
Add integral for bias, not speed
Integral removes steady-state error from friction, gravity, trim error, or load. It also stores past error, so it can create overshoot and long recovery after saturation.
Use anti-windup from the first implementation:
- clamp the integrator,
- stop integrating when output is saturated and error pushes farther into saturation,
- or back-calculate the difference between saturated and unsaturated output.
Record integrator limits in physical units. A magic number without actuator scale is not portable between revisions.
Use derivative carefully
Derivative reacts to slope, so it amplifies noise. Prefer derivative on measurement rather than derivative on error when setpoint steps are common. Filter it deliberately and record the cutoff.
Derivative helps when inertia or delay causes overshoot. It does not fix a noisy sensor, bad sample timing, or loose mechanical coupling.
Check the discrete-time implementation
A sampled PID needs deterministic timing:
[I_k = I_{k-1} + K_i e_k T_s]
[D_k = K_d \frac{y_{k-1} - y_k}{T_s}]
where $T_s$ is the sample period and $y_k$ is the measurement. If the loop period jitters, derivative and integral terms change even when gains do not. Measure loop period under logging enabled and disabled. Logging can change the controller.
Tune against requirements
A tuning run should record:
| Field | Example |
|---|---|
| plant revision | motor, driver, load, supply voltage |
| firmware revision | control code and gain source |
| gains | $K_p$, $K_i$, $K_d$, limits, filter constants |
| step | initial value, target value, duration |
| result | rise time, overshoot, settling time, steady error |
| faults | saturation, thermal limit, resets, dropped samples |
Do not keep gains that only work for one cherry-picked step. Test small, medium, and large commands in both directions, plus disturbance recovery.
Related notes
Measurement and Instrumentation, Design Verification and Test, and IMU Calibration and Drift.
Sources
- Åström and Hägglund, PID Controllers: Theory, Design, and Tuning.
- Brett Beauregard, Improving the Beginner’s PID.
- Control Tutorials for MATLAB and Simulink, PID control.