Skip to main content
Robotics & Embodied AI

⏱ About 20 min20 XP

Feedback Control and PID

If there is one algorithm that appears more often in real deployed robotics than any other, it is the PID controller. Proportional-Integral-Derivative control is found in every industrial robot, every servo motor, every aircraft autopilot, every temperature regulator, and most drone stabilizers. It is not glamorous, not deep-learning-based, and not particularly modern — it was formalized in the 1940s. But it works, it is tunable with physical intuition, and understanding it deeply gives you insight into every control system you will ever encounter.

The Error Signal

Every feedback controller begins with an error signal e(t), defined as the difference between the desired state (setpoint) and the measured actual state: e(t) = r(t) - y(t) where r(t) is the reference (desired) and y(t) is the measured output. If the setpoint is a joint angle of 45 degrees and the encoder reads 42 degrees, the error is +3 degrees. The controller's entire job is to choose a control output u(t) that drives e(t) to zero. The simplest possible controller is proportional control: u(t) = Kp * e(t). Apply a control signal proportional to the error. Large error — large correction. Small error — small correction. Zero error — zero correction. Proportional control works and is used everywhere, but it has a fundamental flaw for many systems: steady-state error. For a joint under constant gravitational load, a purely proportional controller reaches a steady state where the error is nonzero — just small enough that the correction torque exactly balances the gravitational torque. The joint never quite reaches the commanded position. This non-zero residual error in steady state is called steady-state error or offset.

Why Proportional Control Has Steady-State Error

For a proportional-only controller to produce a nonzero output (needed to hold a joint against gravity), there must be a nonzero error e(t) = Kp * u(t). So the controller reaches a balance point where error is small but nonzero — forever. Eliminating steady-state error requires a term that 'remembers' accumulated error over time: the integral term.

The full PID control law is: u(t) = Kp * e(t) + Ki * integral(e(t) dt) + Kd * de(t)/dt Three terms, three gains (Kp, Ki, Kd), three complementary behaviors. The Proportional term Kp * e(t) drives the output in proportion to the current error. It provides the main corrective force. Higher Kp means faster response but can cause overshoot and oscillation if set too high. The Integral term Ki * integral(e(t) dt) integrates the error over time — it sums up all past errors. If the system sits with a small nonzero error, the integral keeps growing, and the integral term keeps pushing until the error is eliminated. This term drives steady-state error to zero. Its drawback: integral windup — if the robot is stuck against a mechanical stop for a long time, the integral accumulates to a very large value and causes violent motion when the robot is freed. The Derivative term Kd * de(t)/dt reacts to the rate of change of error. If the error is decreasing rapidly (the arm is approaching the setpoint fast), the derivative term applies a braking force to prevent overshoot. It provides damping — smoothing out oscillations that proportional control alone would cause. The derivative term is sensitive to sensor noise (because noise introduces high-frequency spikes in de/dt), so it is often applied to the measured output rather than the error, and sometimes filtered.

Flashcards — click each card to reveal the answer

Tuning: How Gains Shape Behavior

PID tuning — choosing Kp, Ki, and Kd — is as much art as engineering, but there are systematic rules. Start with Kp alone. Increase Kp until the response is fast enough. Then increase further until the system starts to oscillate. Back Kp off to about half the oscillation threshold. This is the Ziegler-Nichols heuristic. Add Kd to damp the oscillations the proportional term causes. Kd brings overshoot under control without slowing the initial response much. Add Ki last. Start very small — a little integral goes a long way. Too much Ki causes slow, persistent oscillations as the integral winds up and unwinds. For a joint position controller on a robot arm, typical symptoms of gain misconfiguration are: Too-low Kp: slow, sluggish response; the arm drifts from setpoint under disturbances. Too-high Kp: rapid oscillation ('hunting') around the setpoint; the arm chatters. Too-high Ki: slow oscillation with a period much longer than the proportional oscillation; the arm overshoots, corrects, overshoots the other way. Too-high Kd: amplification of sensor noise; the control signal becomes jagged and the arm trembles. Cascade control is a common extension: a position PID controller sets a velocity setpoint, and a separate (inner) velocity PID controller tracks that velocity setpoint. This two-loop structure — outer position loop, inner velocity loop — improves disturbance rejection because the fast inner loop rejects velocity disturbances before they become position errors.

Complete the descriptions of the three PID terms.

The proportional term provides output in proportion to the error. The integral term eliminates error by summing past errors over time. The derivative term provides by reacting to the rate of change of error.

A robot joint controlled by a proportional-only controller consistently comes to rest 1.5 degrees short of the commanded angle even after a long wait. The most correct diagnosis and fix is:

A drone's altitude controller has Kp = 5, Ki = 0.1, Kd = 2. An engineer notices the drone oscillates slowly in altitude with a period of about 8 seconds after reaching its target height. Kp-driven oscillations at this drone's bandwidth are much faster (< 1 second). What is the most likely cause?

PID Gain Intuition Experiment

  1. Use an online PID simulator (search 'PID simulator interactive' or use a tool like the one at pidtuner.com or the interactive on matlab.com) to explore how gains shape closed-loop response.
  2. Task 1 — Proportional term only: Set Ki = 0, Kd = 0. Vary Kp from 0.5 to 10 in steps of 1. Record: rise time, overshoot (%), and whether the system oscillates. Make a table.
  3. Task 2 — Add derivative: With Kp at the value that caused oscillation in Task 1, set Kd = 1, 3, 5, 10. Observe how Kd damps oscillation. Record the minimum Kd that eliminates oscillation.
  4. Task 3 — Add integral: With your best Kp and Kd from Task 2, add Ki = 0.1, then 1, then 5. Observe how quickly steady-state error is eliminated and at what Ki value overshoot becomes problematic.
  5. Task 4 — Disturbance rejection: Apply a step disturbance to the system with your final gains. Compare how quickly P-only, PD, and PID controllers reject the disturbance.
  6. Deliverables: A table of observations and a one-paragraph written conclusion: what does each gain do, and what happens when it is set too high?