Skip to content
AI360Xpert
Beta
Physical AI & Robotics

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

The error signal measures the gap between desired setpoint and physical state.
The error signal measures the gap between desired setpoint and physical state.

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 θ(t)\theta(t) from the target setpoint θd\theta_d:

e(t)=θd−θ(t)e(t) = \theta_d - \theta(t)

If the shoulder setpoint is θd=45.0∘\theta_d = 45.0^\circ and the optical encoder reports θ(t)=35.0∘\theta(t) = 35.0^\circ, the controller receives an error signal of e(t)=+10.0∘e(t) = +10.0^\circ.

2. Proportional Action: The Virtual Spring

Proportional control acts like a virtual spring pulling toward the target.
Proportional control acts like a virtual spring pulling toward the target.

The Proportional (P) term generates a restoring torque directly scaled to the present error:

uP(t)=Kpe(t)u_P(t) = K_p e(t)

It behaves like a virtual mechanical spring attached between the physical joint and the target. With proportional gain Kp=0.50 N⋅m/degK_p = 0.50\text{ N}\cdot\text{m/deg} and error e=10.0∘e = 10.0^\circ, the motor produces uP=0.50×10.0=5.0 N⋅mu_P = 0.50 \times 10.0 = 5.0\text{ N}\cdot\text{m}. As the joint nears the target, error shrinks, and the restoring torque smoothly decays.

3. The Gravity Offset Defect

Under constant gravity loads, proportional control stalls with permanent steady-state error.
Under constant gravity loads, proportional control stalls with permanent steady-state error.

Proportional-only control fails under continuous environmental loads. Consider our arm holding a coffee mug against a constant gravitational torque of τgrav=5.0 N⋅m\tau_{\text{grav}} = 5.0\text{ N}\cdot\text{m}. Mechanical equilibrium occurs when motor torque balances gravity:

Kpess=τgrav  ⟹  ess=τgravKp=5.00.50=10.0∘K_p e_{\text{ss}} = \tau_{\text{grav}} \implies e_{\text{ss}} = \frac{\tau_{\text{grav}}}{K_p} = \frac{5.0}{0.50} = 10.0^\circ

The joint permanently stalls at θss=35.0∘\theta_{\text{ss}} = 35.0^\circ. To generate the 5.0 N⋅m5.0\text{ N}\cdot\text{m} needed to resist gravity, there must be 10.0∘10.0^\circ of error. If error reached zero, proportional torque would vanish and the arm would collapse.

4. Integral Action: Erasing the Offset

Integral control accumulates past error to eliminate steady-state offset.
Integral control accumulates past error to eliminate steady-state offset.

The Integral (I) term acts as a temporal accumulator, integrating residual error over past time:

uI(t)=Ki∫0te(τ)dτu_I(t) = K_i \int_0^t e(\tau) d\tau

As long as the arm droops below the setpoint (e>0e > 0), the integral term continually increases, steadily ramping motor torque until the arm lifts to θd=45.0∘\theta_d = 45.0^\circ. Crucially, when error reaches zero (e=0e = 0), the accumulated integral memory does not reset—it retains the exact 5.0 N⋅m5.0\text{ N}\cdot\text{m} required to balance gravity, achieving true zero steady-state error (ess=0.0∘e_{\text{ss}} = 0.0^\circ).

5. Derivative Action: The Virtual Damper

Derivative action acts as a viscous damper that opposes rapid motion to brake overshoot.
Derivative action acts as a viscous damper that opposes rapid motion to brake overshoot.

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:

uD(t)=Kdde(t)dt=−Kdθ˙(t)u_D(t) = K_d \frac{de(t)}{dt} = -K_d \dot{\theta}(t)

When the arm moves rapidly toward the target (θ˙>0\dot{\theta} > 0), the derivative of error is negative (e˙<0\dot{e} < 0). This produces an opposing braking torque before the joint crosses the setpoint, preventing overshoot and damping oscillations.

6. The Complete PID Formulation

PID control unifies past accumulation, present reaction, and future anticipation.
PID control unifies past accumulation, present reaction, and future anticipation.

The complete classical PID controller sums all three terms into a unified torque output:

u(t)=Kpe(t)⏟Present Reaction+Ki∫0te(τ)dτ⏟Past Accumulation+Kdde(t)dt⏟Future Anticipationu(t) = \underbrace{K_p e(t)}_{\text{Present Reaction}} + \underbrace{K_i \int_0^t e(\tau) d\tau}_{\text{Past Accumulation}} + \underbrace{K_d \frac{de(t)}{dt}}_{\text{Future Anticipation}}

In discrete microcontroller loops running with sampling interval Δt\Delta t, the integral is approximated as a running sum and the derivative as a backward difference: uk=Kpek+Ki∑ejΔt+Kd(ek−ek−1)/Δtu_k = K_p e_k + K_i \sum e_j \Delta t + K_d (e_k - e_{k-1}) / \Delta t.

7. Step Response Comparison

Tuning PID gains shapes step response between underdamped ringing and critically damped tracking.
Tuning PID gains shapes step response between underdamped ringing and critically damped tracking.

Gains govern the dynamic profile:

  • Underdamped (KpK_p high, KdK_d low): Fast rise time, but exhibits a 22%22\% overshoot and persistent oscillations around 45.0∘45.0^\circ.
  • Overdamped (KdK_d excessively high): Sluggish, non-oscillatory approach taking over 2.0 s2.0\text{ s} to reach setpoint.
  • Critically Damped: Optimal balance achieving maximum speed without overshoot or ringing.

8. Actuator Saturation

Physical motor hardware caps maximum torque, clipping linear control requests.
Physical motor hardware caps maximum torque, clipping linear control requests.

Theoretical control equations assume motors can output unbounded torque. In real hardware, H-bridge amplifiers and motor windings impose physical saturation ceilings: ∣u∣≤umax⁡=20.0 N⋅m|u| \le u_{\max} = 20.0\text{ N}\cdot\text{m}. If an aggressive PID calculation demands 45.0 N⋅m45.0\text{ N}\cdot\text{m}, the driver clips output at 20.0 N⋅m20.0\text{ N}\cdot\text{m}, temporarily breaking the linear feedback assumptions.

9. Integrator Windup and Anti-Windup

Integrator windup during actuator saturation causes severe delayed overshoot.
Integrator windup during actuator saturation causes severe delayed overshoot.

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

Discrete differentiation violently amplifies sensor noise into high-frequency motor chatter.
Discrete differentiation violently amplifies sensor noise into high-frequency motor chatter.

Pure derivative control breaks down in the presence of real sensor noise. Discrete differentiation calculates (ek−ek−1)/Δt(e_k - e_{k-1}) / \Delta t. At a fast sampling rate of Δt=2 ms\Delta t = 2\text{ ms} (500 Hz500\text{ Hz}), a tiny encoder quantization jitter of just Δe=0.10∘\Delta e = 0.10^\circ produces an artificial rate spike of:

ΔeΔt=0.10∘0.002 s=50.0∘/s\frac{\Delta e}{\Delta t} = \frac{0.10^\circ}{0.002\text{ s}} = 50.0^\circ/\text{s}

With derivative gain Kd=0.40K_d = 0.40, this injects a violent torque spike of ±20.0 N⋅m\pm 20.0\text{ N}\cdot\text{m} 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.