Line Following
A line follower reads a few light sensors under its nose and steers to keep the line between them. It is often the first robot people build, and it already shows the core of feedback control.
Two kinds of steering
The two-sensor robot uses on or off steering: if the left sensor sees the line, turn left as hard as you can, and the same for the right. The five-sensor robot works out how far the line is from its center and steers in proportion to that error:
Here \(x_i\) is the sideways position of sensor \(i\) and \(s_i\) is 1 if it sees the line.
What to notice
The two-sensor robot zigzags, because every correction is full strength. It also loses the line on sharp curves at high speed. The five-sensor robot runs smoother, since small errors get small corrections. Too high a \(K_p\) makes it wobble, and too low makes it drift wide on curves. Speed makes everything harder, since the robot travels further between each look at the line.
This is the same idea as PID control. Proportional steering is the P term, and adding a D term would damp the wobble.