🔍🔩 Parts bench
19 lessons

Capstone: Tune the Line Follower

Everything so far on one small robot: sensors report the line, PWM drives the wheels, and your gains decide between lurching, wobbling and one clean fast lap.

lesson 3 of 3 in this unit

Builds on: 3.2 PID: Three Letters That Run the World0.2 PWM: How a Computer Whispers to a Motor1.1 DC Motors: Fast, Weak and Hungry

Same idea, other course:Spark: building the hardware itself

The classic first robot, and why

A line follower is a robotics degree in miniature: reflectance sensors under the nose report where a dark line lies (sense), a controller turns that into a steering decision (think), and two PWM duty cycles steer by wheel-speed difference (act) — around again, hundreds of times a second. Every part is one you now know by name.

From five sensors to one error

The sensor array yields one number: the line’s position under the robot, from −2 (far left) to +2 (far right). Centre reads zero — and zero is the setpoint. The whole seeing-problem compresses into the error e, and steering becomes last lesson’s formula:

steer = Kp·e + Kd·de/dtleft wheel slows by steer, right wheel speeds by it — PD, no I: a moving robot carries no steady gravity-like pull

Why no integral? A line follower rarely suffers constant one-sided disturbance — its error swings through zero constantly — so the grudge account would mostly collect noise and windup. Real racers run PD. (If one wheel were weaker than the other, that would be a steady pull, and a small I would earn its keep: know the rule, then know when you’re in the exception.)

Speed is the difficulty dial

At crawling pace, almost any Kp follows any curve. Raise the speed and every sin gets expensive: corners arrive faster than the loop corrects, P-only tuning oscillates into oblivion, and the D term stops being optional. The capstone is exactly this climb: tune clean at low speed, then raise the pace and re-earn stability with better gains. Your lap time and off-line count are the honest judges.

This transfers whole

Swap “line position” for “heading to waypoint” and this exact structure drives warehouse robots down aisles. Tune this well and you have tuned most of mobile robotics’ inner loop once already.

⚗️ Lab — The Racing Line

A top-down track with straights, sweepers and one hairpin. Sliders for speed, Kp and Kd; meters for lap time, worst error and departures.

  • Start slow, Kd = 0: find a Kp that laps cleanly. It works because the sensor bar rides ahead of the axle — free damping at crawling speed. Raise speed and watch that gift erode.
  • Bring in Kd and re-tame it. Push speed again. Repeat — this ladder is the whole capstone.
  • The checklist below is your race stewards: work through it and the lesson completes.
90 px/s
2.5
0.00
Verdict
clean lap in 16.0 s
Ø error
20 % of the lane
Recipe
raise speed → wobble → add Kd → repeat

Tuning checklist — 0 / 5