LQR

Also known as: Linear-quadratic regulator

On this page 7

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.

SymbolMeaningRequirement
A, BSystem and input matrices of the linearized modelPair must be stabilizable
QWeight on state deviationSymmetric positive semidefinite
RWeight on control effortSymmetric positive definite
PSolution of the Riccati equationSymmetric positive semidefinite
KOptimal feedback gainComputed offline, applied online
Elements of the LQR problem

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.

ChangeEffect on responseSide effect
Increase Q for positionFaster, tighter position correctionHigher torques and more noise sensitivity
Increase Q for velocityMore damping, less overshootSlower approach to the target
Increase RSmaller, smoother inputsSlower response, larger errors
Decrease RAggressive controlRisk of saturation and exciting unmodeled dynamics
Scale Q and R togetherNo change in gainOnly the cost value changes
Effect of changing LQR weights

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.

MethodModel neededConstraintsOnline costTypical robotic use
PIDNo explicit modelNoneVery lowSingle joints, motor current loops
LQRLinear state-space modelNot handledMatrix multiplyBalancing, hover, stabilization
LQGLinear model with noise statisticsNot handledLowLQR with a Kalman filter for partial measurements
Model predictive controlModel, often linear or nonlinearExplicitly handledOptimization each cycleLocomotion, vehicles near limits
Iterative LQRNonlinear modelSoft, through costModerateTrajectory optimization
LQR and neighboring control approaches

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.

LimitationConsequenceTypical response
Linear model onlyPerformance degrades far from the linearization pointGain scheduling or time-varying LQR
No constraintsInputs or states can exceed limitsModel predictive control or saturation handling
Full state requiredUnmeasured states must be estimatedState estimation with a Kalman filter
Model errorsOptimality and margins erodeSystem identification, robustness checks
Weights lack physical unitsTuning can feel abstractBryson’s rule as a starting point
Common LQR limitations and responses

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.