Feedback Control Systems
A motor told to spin at 60 radians per second will not do so exactly: load changes, friction varies, the battery sags, and the model of the motor is approximate. Feedback control solves this by measuring what actually happens, comparing it with what should happen, and adjusting the command continuously. The same principle keeps drones level, robot arms on their paths, thermostats at temperature, and servers at target utilization.
Control code looks simple — a PID controller is a few lines — but small details decide whether a system is smooth, sluggish, oscillating, or dangerous: the sample rate, how the derivative is computed, what happens when the actuator saturates, and how gains are tuned. This page covers those details and where more advanced, model-based controllers fit.
TL;DR
- A controller compares a setpoint with a measurement and commands an actuator to reduce the error.
- PID: proportional reacts to current error, integral removes steady-state error, derivative damps rapid change.
- Run controllers at a fixed, fast enough rate; filter the derivative and take it on the measurement to avoid kicks.
- Actuators saturate; use anti-windup so the integral does not grow while the output is limited.
- Tune systematically, add feedforward for known effects, and use cascaded loops (position → velocity → current).
- For multivariable or constrained problems, use state-space methods such as LQR and model predictive control, tested in simulation first.
Quick Example
A discrete PID controller with derivative filtering and anti-windup, controlling a simulated motor:
Core Concepts
The Loop
Open-loop control sends commands without measuring results; it works only when the model is accurate and disturbances are small. Closed-loop feedback corrects for both, at the cost of possible instability if tuned poorly.
PID Control
Many real controllers are PI (no derivative) because derivatives amplify noise; motion controllers often use PD plus feedforward.
Discrete-Time Implementation
Controllers run in software at a fixed sample rate, often 100 Hz to several kHz for motors, from a timer interrupt or a real-time task. Keep the period constant (jitter acts like noise), make it roughly ten times faster than the dynamics you control, and use the actual dt. Take the derivative of the measurement rather than the error to avoid spikes when the setpoint changes, and low-pass filter it. On microcontrollers, mind fixed-point scaling and overflow. See Real-Time Operating Systems and Embedded C.
Saturation and Anti-Windup
Every actuator has limits: maximum voltage, current, torque, or speed, and often rate limits. When the output saturates, the error persists and a naive integral keeps growing (windup), causing large overshoot once the system catches up. Anti-windup strategies include conditional integration (as in the quick example), clamping the integral, and back-calculation that bleeds off the integral based on the difference between commanded and actual output.
Stability and Tuning
A stable closed loop returns to the setpoint after disturbances; an unstable one oscillates with growing amplitude. Delay, high gains, and slow sampling push systems toward instability. Tuning approaches:
- Manual tuning: raise Kp until response is fast with slight overshoot, add Ki to remove offset, add Kd for damping if needed.
- Ziegler–Nichols and relay autotuning: rules of thumb from measured oscillation; usually aggressive and need refinement.
- Model-based tuning: identify a model (step response, frequency response) and choose gains for desired response, phase margin, and bandwidth.
Evaluate step responses (rise time, overshoot, settling time, steady-state error) and disturbance rejection, not only tracking.
Feedforward and Cascades
Feedforward adds a command computed from known physics — gravity compensation, friction, required acceleration from the trajectory — so feedback only corrects the remainder. Cascaded loops nest controllers: an outer position loop commands velocity, a middle velocity loop commands current, and an inner current loop runs fastest. Each inner loop should be several times faster than the one around it. See Robot Kinematics and Dynamics.
Model-Based Control
MPC handles constraints explicitly but must solve an optimization within each control period; real-time feasibility and fallback behavior when the solver is slow are part of the design.
Testing Controllers
- Simulation with realistic delays, noise, saturation, and model errors.
- Hardware-in-the-loop tests running controller code against simulated plants.
- Step and disturbance tests on real hardware at low gains and limited power first.
- Safety limits independent of the controller: current limits, position limits, watchdogs, and emergency stops. See Robot Safety and Fleet Operations.
- Logging of setpoints, measurements, outputs, and saturation at the control rate for analysis.
Best Practices
Run at a Fixed Rate
Execute control loops from timers or real-time tasks with consistent periods, and monitor timing jitter.
Always Handle Saturation
Model actuator limits in simulation and implement anti-windup in every integrating controller.
Use Feedforward for Known Physics
Compensate for gravity, friction, and planned accelerations so feedback gains can stay moderate.
Tune and Test Incrementally
Start with low gains and limited power, record responses, and change one parameter at a time.
Common Mistakes
Integral Windup
Derivative Kick and Noise
Variable Loop Timing
FAQ
What is a PID controller?
A feedback controller that computes its output from three terms: proportional to the current error, the integral of past error, and the derivative of the error or measurement. It is the most widely used controller in practice.
What is integral windup?
When an actuator saturates, the error persists and the integral term keeps accumulating. When the system recovers, the large integral causes overshoot. Anti-windup methods stop or reduce integration during saturation.
How fast should a control loop run?
Usually around ten times faster than the dynamics being controlled, and faster for inner loops in a cascade. Motor current loops often run at kilohertz rates; position loops for slow mechanisms can run much slower.
When should I use MPC instead of PID?
When you have multiple interacting inputs and outputs, important constraints such as actuator or safety limits, and a usable model — and enough computation to solve the optimization within each control period.
Do I need a model to tune a controller?
Not always; many PID loops are tuned experimentally. A model — even a simple first- or second-order one identified from a step response — makes tuning faster, safer, and more predictable.
Related Topics
- Robotics & Autonomous Systems — The robotics software stack
- Robot Kinematics and Dynamics — Models used for feedforward and control
- Embedded C — Implementing controllers on microcontrollers
- Real-Time Operating Systems — Running loops at fixed rates
- Microcontrollers — Timers, PWM, and encoders
- Probability and Linear Algebra for Computing — State-space and estimation math
- Model Predictive Control — Constrained, receding-horizon optimal control
- Drone Autopilot Systems — Cascaded control loops in flight controllers