PID Control Intuition and Practical Tuning
PID control has been around for over a century, and honestly, it's still the workhorse running underneath most robots you've ever seen. Once you stop treating Kp, Ki, and Kd as mysterious tuning knobs and picture them as a physical spring, a shock absorber, and a patient memory bank, tuning stops feeling like guesswork.
Core ideas covered in this module
- Proportional (spring) & Derivative (damper)
- Integral action & windup
- Overshoot, settling time & sensor noise
P is a spring, D is a shock absorber
The Proportional term (Kp · e) acts like an invisible rubber band or coil spring tied between the arm and the target angle. Crank Kp up and the spring gets stiffer: the arm snaps toward the target faster and sags less under gravity. Crank it too high without anything to slow the arm down, though, and the arm flies right past the target and bounces up and down like a car with blown shocks.
That's where the Derivative term (Kd · ė) comes in. Instead of looking at where the arm is, D looks at how fast the error is changing — essentially how fast the joint is moving. It behaves like a viscous oil damper or shock absorber, resisting rapid motion so the arm glides onto the target without ringing.
I cleans up steady-state droop — until it winds up
Even a well-damped PD controller still sags slightly against constant gravity, because a spring has to stay stretched to hold weight. The Integral term (Ki · ∫ e dt) fixes that by keeping a running sum of past error over time. As long as the arm sits even half a degree low, that sum keeps growing and quietly adds extra upward torque until the steady-state error reaches zero.
The catch shows up when something blocks the arm or the motor hits its torque limit. While the arm is pinned, the integral sum keeps piling up like a coiled spring — a headache called integral windup. The moment the obstacle moves, that huge stored integral blasts the arm into a nasty overshoot.
Interactive lab
Gravity-Loaded Single-Joint Arm PID Tuner
marimo· LiveWhy cranking D too high hurts on real encoders
In a clean simulation, derivative gain feels like free stability — crank Kd up and oscillations vanish. On real hardware, joint encoders measure position in discrete ticks and carry electrical jitter. Taking a numerical derivative (Δθ / Δt) amplifies high-frequency sensor noise by 1/Δt.
If your loop runs at 1 kHz and Kd is too aggressive, the motor starts buzzing, heating up, and vibrating against phantom velocity spikes. That's why practical controllers low-pass filter the velocity estimate and keep Kd just high enough for clean damping.
Parallel PID control law
τ = Kp · e(t) + Ki · ∫ e(τ) dτ + Kd · (de/dt)
P pulls proportionally to current error (spring), I accumulates persistent error over time (droop remover), and D opposes fast motion (damper).
Your robot arm reaches its target angle quickly, but overshoots and rings back and forth five times before settling. Which gain adjustment fixes that ringing first?
Most quadrupeds and manipulators trained with reinforcement learning actually output target joint angles into a fast PD loop (Ki = 0, moderate Kp and Kd) so the robot stays compliant instead of fighting contacts with a winding integrator.
Hands-On Python Notebook
02 · Gravity-Loaded PID Tuning & Windup Lab
Tune Kp, Ki, and Kd on a gravity-loaded pendulum arm, observe integral windup under torque saturation, and test anti-windup clamping.
Try this on your own inside the notebook
- Trigger integral windup with a tight torque limit and add anti-windup clamping
- Add high-frequency encoder noise and inspect derivative kick on Kd
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-4/02_pid_control_tuning.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.