Robotics · Step 5 of 8 · 6 min
Control: feedback and PID
You understand how a robot corrects itself, and what P, I and D each do.
Open loop and closed loop
Open loop means you send a command and hope. Run both motors at the same power and the robot still drifts, because no two motors are identical.
Closed loop means you measure the result and correct. The difference between where you want to be and where you are is the error. Feedback control is about shrinking that error, again and again.
P, I and D
P, proportional, pushes harder the bigger the error. Alone it often overshoots or settles short of the target.
I, integral, adds up the error over time. It removes a small steady error, such as a robot always sitting slightly left of a line. Too much causes slow swings.
D, derivative, reacts to how fast the error is changing. It acts like a brake and calms overshoot, but it amplifies sensor noise.
Tuning in practice
Start with only P. Raise it until the robot responds briskly and starts to wobble. Add D to calm the wobble. Add a little I only if a steady offset remains.
Cap the integral term so it cannot grow without limit while a motor is stuck. This is called integral windup, and it causes sudden lurches once the robot is free.
Try it
Tune a controller without hardware
- 1.Ask a chatbot for a short Python script that simulates a cart moving to a target with a PID controller and plots the result.
- 2.Run it free in Google Colab.
- 3.Try P only, then P plus D, then all three. Watch overshoot and settling time change.
Write a Python script for Google Colab that simulates a 1D cart moving to position 10 with a PID controller and plots position over time. Put Kp, Ki and Kd at the top so I can change them. Keep it under 40 lines.