Understand
Too Much, Too Little
In the code, Priya found a number called the gain. Each time the robot sensed an error, it steered by the error multiplied by the gain.
With a small gain, the robot corrected gently, so gently that it drifted off the line before it ever caught up. Sluggish. With a medium gain, it curved back to the line and settled on it. With a big gain, it corrected so hard that it flew past the line to the other side, which created a new error in the opposite direction, which it also overcorrected. That was the zig-zag. Too much correction does not fix a problem faster. It creates a new problem on the other side.
There was one more piece. The robot’s sensor only updated a few times a second, so it was always steering based on where it had been a moment ago. Old information plus strong reactions is a recipe for wild swings.
Use the loop lab to see it. Try a tiny gain, a medium gain, and a big gain. Then switch on the delay and watch what happens to the same settings.
Try it
The loop lab
The robot starts 10 cm off the line. Each step it steers by (gain x the error it sees). Find a gain that settles smoothly, then add a delay.
Overshoots, then settles
It crosses the line once or twice, then calms down. Fast, a little jumpy.