Loading header...

PID Control

PID control is the most common feedback algorithm in practical mechatronics. It combines proportional, integral, and derivative actions to reduce error, remove steady offset, and add damping.

Learning Objectives

By the end of this lesson, you should be able to explain P, I, and D terms, write a discrete PID loop, recognize windup and derivative noise, and tune a simple axis safely.

PID Equation

Continuous PID is commonly written as:

$$
u(t)=K_p e(t)+K_i\int e(t)dt+K_d\frac{de(t)}{dt}
$$

where u(t) is actuator command and e(t) is setpoint minus measured output.

In firmware, the loop runs at a fixed sample time Ts:

error = setpoint - measurement;
integral += error * Ts;
derivative = (error - previous_error) / Ts;
command = Kp * error + Ki * integral + Kd * derivative;
previous_error = error;

What Each Term Does

Term Effect Risk
P reacts to present error oscillation if too high
I removes steady-state error windup and slow recovery
D predicts error change and adds damping amplifies noise

Saturation and Windup

Actuators have limits. If the command saturates but the integral keeps growing, the loop may overshoot badly when it finally recovers. This is integral windup.

Use anti-windup: clamp the integral, pause integration while saturated, or back-calculate the integral from the saturated command.

Tuning Workflow

  1. Disable integral and derivative.
  2. Increase Kp until response is fast but not unstable.
  3. Add Kd if overshoot or oscillation needs damping.
  4. Add small Ki to remove final error.
  5. Test steps in both directions and with load changes.
  6. Record plots before and after every change.

Sample Time and Filtering

PID assumes regular timing. Jitter changes derivative and integral behavior. Use a fixed-rate control task. Filter noisy measurements carefully; too much filtering adds delay and can destabilize the loop.

Common Mistakes

  • Starting with all three gains nonzero.
  • Using derivative directly on noisy error.
  • Forgetting actuator saturation and windup.
  • Changing sample time without retuning gains.
  • Tuning unloaded and then expecting loaded behavior to match.

Summary

PID works because P reacts, I corrects offset, and D damps change. Real PID design is mostly about limits: actuator saturation, sensor noise, timing, delay, friction, and safe tuning steps.

Further Reading

  • Astrom and Hagglund, PID Controllers.
  • Brett Beauregard, Improving the Beginner's PID.
  • Control Engineering, PID tuning fundamentals.

Mind Map

mindmap root((PID Control)) Core concept P present error I accumulated error D error rate Formulas u equals Kp e plus Ki integral e dt plus Kd de dt Derivative approx delta e over Ts Integral sum error times Ts Applications Position loop Speed loop Temperature Balancing Design rules Fixed sample time Clamp command Anti windup Filter carefully Practical checks Step response Saturation time Noise on derivative Load change Common mistakes Too much Ki No output limits Derivative noise Retune ignored after Ts change