LQR, the linear-quadratic regulator, is an optimal control method that computes a state-feedback gain matrix for a linear system by minimizing a quadratic cost that weighs deviations of the state against the control effort used to correct them. In robotics control systems, LQR is a standard tool for stabilizing balancing robots, quadrotors, manipulators and legged robots around an operating point or along a planned trajectory.
Instead of tuning individual gains by hand, as with a PID loop, the engineer specifies what matters: how much each state error costs and how expensive each actuator command is. The LQR solution then yields the feedback law u = -Kx, which is optimal for that cost and, under mild conditions, guaranteed to stabilize the linear model.
How LQR computes the optimal gain
LQR starts from a linear state-space model dx/dt = Ax + Bu, where x is the state vector, such as positions and velocities, and u is the input vector, such as motor torques. It minimizes the infinite-horizon cost J, the integral of x^T Q x + u^T R u over time.
The optimal input is a linear function of the full state, u = -Kx, with K = R^-1 B^T P. The matrix P is the unique stabilizing solution of the continuous algebraic Riccati equation A^T P + P A - P B R^-1 B^T P + Q = 0. For digital controllers sampled at a fixed period, the discrete-time version uses the discrete algebraic Riccati equation instead.
| Symbol | Meaning | Requirement |
|---|---|---|
| A, B | System and input matrices of the linearized model | Pair must be stabilizable |
| Q | Weight on state deviation | Symmetric positive semidefinite |
| R | Weight on control effort | Symmetric positive definite |
| P | Solution of the Riccati equation | Symmetric positive semidefinite |
| K | Optimal feedback gain | Computed offline, applied online |
A further condition is that the state weighting must observe every unstable mode, formally that the pair formed by A and the square root of Q is detectable. Numerical libraries for control solve the Riccati equation in milliseconds for typical robot models with a few to a few dozen states.
Tuning LQR with the Q and R matrices
LQR tuning means choosing Q and R to express the trade-off between tracking accuracy and actuator effort. Raising a diagonal entry of Q makes the controller correct that state more aggressively; raising an entry of R makes the corresponding actuator gentler.
A common starting point is Bryson’s rule: set each diagonal entry of Q to one over the square of the largest acceptable deviation of that state, and each entry of R to one over the square of the largest acceptable input. The designer then iterates in simulation, observing overshoot, settling time and actuator saturation.
| Change | Effect on response | Side effect |
|---|---|---|
| Increase Q for position | Faster, tighter position correction | Higher torques and more noise sensitivity |
| Increase Q for velocity | More damping, less overshoot | Slower approach to the target |
| Increase R | Smaller, smoother inputs | Slower response, larger errors |
| Decrease R | Aggressive control | Risk of saturation and exciting unmodeled dynamics |
| Scale Q and R together | No change in gain | Only the cost value changes |
Only the ratio between Q and R affects the gain, which makes relative weighting the real design variable. Off-diagonal entries can penalize combinations of states, but most practical designs keep both matrices diagonal for clarity.
LQR compared with other control methods
LQR occupies a middle ground between classical loop tuning and full online optimization. It handles multiple inputs and coupled states naturally, but it does not enforce constraints.
| Method | Model needed | Constraints | Online cost | Typical robotic use |
|---|---|---|---|---|
| PID | No explicit model | None | Very low | Single joints, motor current loops |
| LQR | Linear state-space model | Not handled | Matrix multiply | Balancing, hover, stabilization |
| LQG | Linear model with noise statistics | Not handled | Low | LQR with a Kalman filter for partial measurements |
| Model predictive control | Model, often linear or nonlinear | Explicitly handled | Optimization each cycle | Locomotion, vehicles near limits |
| Iterative LQR | Nonlinear model | Soft, through cost | Moderate | Trajectory optimization |
The infinite-horizon LQR solution is in fact what a model predictive controller converges to when constraints are inactive and the horizon is long. Many MPC designs therefore use the LQR cost-to-go matrix P as their terminal cost.
Robustness and practical implementation
Continuous-time LQR with full state measurement has notable robustness guarantees: for each input channel, it tolerates a gain increase of any size, a gain reduction down to one half, and a phase margin of at least 60 degrees. These margins explain much of its popularity.
The guarantees disappear when the state is estimated rather than measured. Combining LQR with a Kalman filter, as in LQG control, can produce arbitrarily small margins, so designs with observers must be checked explicitly for robustness, for example with loop transfer recovery or simulation under model uncertainty.
- Linearize carefully around the actual operating point, such as the upright position of a balancing robot.
- Add integral states when steady disturbances, like a payload or slope, must be rejected without offset.
- Use gain scheduling or time-varying LQR when the robot moves far from one operating point.
- Clip inputs to actuator limits and verify behavior during saturation, which LQR itself ignores.
- Match the sampling period of the discrete design to the real control loop, often 200 Hz to 1 kHz in robots.
Limitations of LQR
LQR is optimal only for the linear model and the chosen cost. Its practical limitations follow from those two assumptions.
| Limitation | Consequence | Typical response |
|---|---|---|
| Linear model only | Performance degrades far from the linearization point | Gain scheduling or time-varying LQR |
| No constraints | Inputs or states can exceed limits | Model predictive control or saturation handling |
| Full state required | Unmeasured states must be estimated | State estimation with a Kalman filter |
| Model errors | Optimality and margins erode | System identification, robustness checks |
| Weights lack physical units | Tuning can feel abstract | Bryson’s rule as a starting point |
Despite these limits, LQR remains a reliable baseline. Even teams that deploy model predictive control often design an LQR first to understand the dynamics and to provide a fallback controller.
A non-technical view
Imagine balancing a broom upright on your hand. You constantly decide how much to move your hand, trading off how upright the broom stays against how wildly you are willing to move.
LQR is a mathematical way to make that decision ahead of time. The engineer states what matters, such as keeping the angle small without using too much motor power, and the method calculates the best reaction for every possible situation. The robot then simply applies that recipe many times per second.
A concrete example
A university robotics team builds a two-wheeled self-balancing robot for indoor delivery. Its state contains the body tilt angle, tilt rate, wheel position and wheel velocity, and its inputs are the torques of two wheel motors.
The team linearizes the dynamics around the upright position and applies Bryson’s rule, allowing about 5 degrees of tilt and a limited motor torque as reference values. After solving the discrete Riccati equation for a 500 Hz loop, they adjust the weights in simulation until a push recovers within about a second without saturating the motors. An integral state on wheel position removes drift on slightly sloped floors.
On the real robot, the LQR controller keeps the robot balanced while carrying payloads of different weights, and a Kalman filter fuses the inertial sensor and wheel encoders to supply the estimated state.