P Controller
A line-following robot has exactly one thing it can sense that matters: how far it has drifted sideways from the line. Everything the controller does is built on turning that single number into a steering command.
The Idea
Section titled “The Idea”Let be the robot’s lateral offset from the line, and be where it wants to be. The error is simply how far off it is:
A proportional (P) controller reacts to that error in the most direct way possible — it steers harder the further off the line the robot is, and it does nothing once the error is zero:
Here is the steering command and is the proportional gain — the one knob this controller has. That command doesn’t move the robot sideways directly; it changes the robot’s heading, which then carries it back toward the line as it drives forward:
The heading is clamped to because a real steering mechanism has a physical limit — the robot cannot instantly point straight sideways no matter how large the error is.
Why It Oscillates
Section titled “Why It Oscillates”Notice that heading integrates the steering command rather than jumping straight to it. That integration is inertia: once the robot has turned toward the line, it keeps that heading even after the error shrinks, so it overshoots, has to correct back the other way, overshoots again, and so on. A pure P controller has no term that anticipates or damps this — that’s the job of the D term in a full PID controller — so on its own it tends to oscillate around the line rather than settle smoothly onto it.
Try It
Section titled “Try It”Drag the slider to change and watch the same robot, starting at the same offset, respond differently. The live readout below the canvas shows the exact numbers behind the animation at each instant.
steering command = Kp × error
This is the same model implemented in gui.py — download it and run python3 gui.py to play with it as a desktop Tkinter app instead of in the browser.