PID Control
A PID controller looks at the error between where the robot is and where it should be, and decides how hard to push. Each of its three terms fixes a different problem.
The controller
Here \(e(t)\) is the error, the target position minus the robot position, and \(u(t)\) is the push the controller asks the motor for.
What to notice
P only. The robot moves toward the target, but with high Kp it overshoots and swings back and forth. With friction on, it also stops short of the flag, because a small error makes too small a push to beat friction. That gap is steady-state error.
Add D. The derivative term pushes against fast motion, like a brake. The swinging dies out and the overshoot shrinks.
Add I. The integral term adds up error over time, so a small error that lasts eventually builds enough push to close the gap. Too much Ki brings the overshoot back.