Blog

PID control explained without the scary math

Alessandro Panait·

PID is the most useful control idea in robotics, and it is far simpler than it sounds. It answers one question: given how wrong I am, how hard should I correct?

The error

First, measure the error: the difference between where you are and where you want to be. A line-following robot's error is how far the line is from the center of its sensors.

The three terms

  • P (Proportional): correct in proportion to the current error. Big error, big correction. Alone, this makes the robot wobble around the target.
  • I (Integral): add up past error. This fixes a robot that consistently sits slightly off, for example drifting on a long curve. Often small or unused.
  • D (Derivative): react to how fast the error is changing. This is the damping that kills the wobble. It is what makes P smooth.

Add the three together and you get one number: how hard to steer.

Tuning, the practical recipe

  1. Set I and D to zero. Raise P until the robot follows but visibly oscillates.
  2. Raise D until the oscillation stops. Too much D makes it twitchy on straights.
  3. Add a little I only if you see a steady offset. Many robots run fine with I = 0.
  4. Raise the base speed, then re-tune. Gains that work slow do not work fast.

The mindset shift

A beginner robot uses "if line is left, turn left" (bang-bang), and it wobbles like a shopping cart. PID replaces that with a smooth, proportional response. It is the single biggest upgrade from a jerky robot to one that glides. You can practice PID tuning with no hardware in our free Rescue Line Simulator.

Comments (0)