Visual explainer
Feedback Control and PID
Master proportional, integral, and derivative control, understand steady-state gravity droop, and discover why derivative noise causes chatter.
1. The Real-Time Error Signal
Feedback control continuously measures the discrepancy between what the robot should do and what its body is actually doing. At every sampling tick, a comparator subtracts the measured joint angle from the target setpoint :
If the shoulder setpoint is and the optical encoder reports , the controller receives an error signal of .
2. Proportional Action: The Virtual Spring
The Proportional (P) term generates a restoring torque directly scaled to the present error:
It behaves like a virtual mechanical spring attached between the physical joint and the target. With proportional gain and error , the motor produces . As the joint nears the target, error shrinks, and the restoring torque smoothly decays.
3. The Gravity Offset Defect
Proportional-only control fails under continuous environmental loads. Consider our arm holding a coffee mug against a constant gravitational torque of . Mechanical equilibrium occurs when motor torque balances gravity:
The joint permanently stalls at . To generate the needed to resist gravity, there must be of error. If error reached zero, proportional torque would vanish and the arm would collapse.
4. Integral Action: Erasing the Offset
The Integral (I) term acts as a temporal accumulator, integrating residual error over past time:
As long as the arm droops below the setpoint (), the integral term continually increases, steadily ramping motor torque until the arm lifts to . Crucially, when error reaches zero (), the accumulated integral memory does not reset—it retains the exact required to balance gravity, achieving true zero steady-state error ().
5. Derivative Action: The Virtual Damper
While P pushes and I lifts, the Derivative (D) term acts as a virtual shock absorber or viscous dashpot, opposing the rate of change of error:
When the arm moves rapidly toward the target (), the derivative of error is negative (). This produces an opposing braking torque before the joint crosses the setpoint, preventing overshoot and damping oscillations.
6. The Complete PID Formulation
The complete classical PID controller sums all three terms into a unified torque output:
In discrete microcontroller loops running with sampling interval , the integral is approximated as a running sum and the derivative as a backward difference: .
7. Step Response Comparison
Gains govern the dynamic profile:
- Underdamped ( high, low): Fast rise time, but exhibits a overshoot and persistent oscillations around .
- Overdamped ( excessively high): Sluggish, non-oscillatory approach taking over to reach setpoint.
- Critically Damped: Optimal balance achieving maximum speed without overshoot or ringing.
8. Actuator Saturation
Theoretical control equations assume motors can output unbounded torque. In real hardware, H-bridge amplifiers and motor windings impose physical saturation ceilings: . If an aggressive PID calculation demands , the driver clips output at , temporarily breaking the linear feedback assumptions.
9. Integrator Windup and Anti-Windup
While an actuator is saturated at its torque ceiling, error remains positive. If the integrator continues running unchecked, its accumulated sum balloons to massive values. When the arm finally reaches the target, this wound-up internal charge prevents the motor from reversing, causing the arm to fling wildly past the setpoint. Practical controllers enforce anti-windup clamping: freezing integration whenever the actuator is saturated.
10. Where It Breaks
Pure derivative control breaks down in the presence of real sensor noise. Discrete differentiation calculates . At a fast sampling rate of (), a tiny encoder quantization jitter of just produces an artificial rate spike of:
With derivative gain , this injects a violent torque spike of straight into the motor coils. The actuator chatters like a jackhammer, stripping gearbox teeth and destroying motor drivers unless low-pass derivative filters are applied.
The Quick Version
- The error signal subtracts physical state from setpoint at each sample tick.
- Proportional control behaves like a virtual spring scaled to present error.
- P-only control permanently sags under constant gravity loads to balance holding torque.
- Integral control sums past error to eliminate steady-state offsets under load.
- Derivative control provides viscous damping to brake motion and prevent overshoot.
- The complete PID formula coordinates present reaction, past memory, and future rate.
- Tuning gains balances underdamped oscillation against overdamped sluggishness.
- Physical voltage and current caps saturate maximum achievable actuator torque.
- Integrator windup during saturation causes massive delayed overshoots without clamping.
- Discrete differentiation amplifies high-frequency encoder noise into destructive motor chatter.