Skip to content
RoboLearn
Not completed

Feedback control and PID

Control & autonomyIntermediate40 minTune a P controller ↓Before this: Conditional logic (if / else), IR line sensors

What you’ll learn

  • Why on/off (“bang-bang”) control wobbles
  • P, I and D in plain words
  • How to tune a controller step by step

Bang-bang control

The two-sensor line follower only knows “left”, “right” or “centre”, so it jerks between full turns: bang-bang control. It works, but it zig-zags and can’t go fast.

Error

Proportional control needs a number: the error, how far you are from where you want to be. In the simulator, linePosition() gives the line’s position under a 5-sensor bar, from −1 (far left) to 1 (far right), so the error is just that value (target = 0).

P: proportional

correction = Kp × error

Small error → small correction; big error → big correction. Too little Kp and the robot drifts off on curves; too much and it oscillates.

D: derivative

+ Kd × (error − lastError)

Reacts to how fast the error is changing, which damps the wobble, like a shock absorber.

I: integral

+ Ki × (sum of all errors)

Fixes a small error that stays for a long time (one motor slightly weaker). Line followers often don’t need it; balancing robots and heaters do.

Tuning recipe

  1. Set Ki = Kd = 0. Increase Kp until it follows well but starts to wobble.
  2. Add Kd until the wobble calms down.
  3. Only if it settles slightly off-target, add a little Ki.
  4. Change one number at a time and note what happens.

Finished this lesson?