LQR: decide what a good balance costs
LQR calculates a state-feedback gain from a linear model and a stated tradeoff between state error and control effort.
Read the state and input weights in an LQR cost without treating them as direct speed knobs.
We can choose feedback and observer poles. But a faster response may demand more force. LQR makes this design tradeoff explicit.
Review the previous lesson: Luenberger observers and separationFirst, picture it
Keeping the pole vertical is not the only goal: the cart can roll off the rail while the angle looks fine. You might penalize position, velocity, angle and angular velocity, but also avoid demanding enormous motor force. LQR turns those preferences into a mathematical cost.
Build the idea step by step
LQR means linear-quadratic regulator. Linear describes the model; quadratic means we square state errors and inputs when counting cost. The state weight Q says which deviations matter. The input weight R says how costly control effort is. The method finds a feedback gain that minimizes accumulated cost under the stated assumptions. Weights are design choices, not direct settings for settling time. Use consistent scales when position, speed, and angle have different units.
Read the equations
LQR chooses a feedback gain to minimize accumulated state and input costs for a stated linear model. Q is chosen so state cost cannot be negative; R gives every nonzero input a positive cost. The model must also allow unstable states to be controlled and appropriately penalized.
What the symbols mean
- total cost, not rotor inertia in this lesson
- state deviation and control input
- weights that make state and input costs comparable
- feedback gain calculated from model and weights
- transpose: turns a column into a row
The worked example is a continuous-time scalar integrator. The cart-pole lab computes a discrete-time gain for its design model and applies it to a nonlinear, force-limited simulation. The simple square-root formula does not apply to that full model, and its constrained motion is not guaranteed optimal.
One state, one cost tradeoff
Use the normalized scalar integrator: state rate equals input. For this special continuous-time example, the optimal gain is the square root of Q divided by R.
With Q and R both 1, gain is 1. The closed-loop state decays with a one-unit time constant.
Keeping Q at 1 and raising R to 4 makes gain 0.5. From state 2, initial input becomes minus 1 instead of minus 2: less effort, slower decay. General matrix problems require solving a Riccati equation.
More detail and model assumptions
What changes when you change Q or R?
Increasing an angle penalty asks the linear design to care more about angle error relative to other terms. Increasing the force penalty asks it to spend less input. These are design preferences, not guaranteed monotonic changes in every nonlinear, saturated time trace. Compare actual angle, position and applied force after the same initial tilt and kick.
A full-state LQR assumes the controller knows all needed states. If the hardware measures only position and angle, an observer must estimate velocities. That is the bridge to the following Kalman and LQG lectures.
Connect the example to the lab
Pin one cart-pole LQR run, change only the angle cost or force cost, and compare position recovery, angle and applied force after the same kick.
Tune the LQR weightsMake a prediction before moving a control.
- PREDICTWill prioritizing angle reduce cart travel or increase force?
- CHANGE ONE THINGPin one LQR run; change only one Q or R control.
- OBSERVECompare pole angle, cart position, applied force and rail status.
- EXPLAINDescribe the tradeoff rather than declaring a universal best weight.
LQR does not design swing-up and does not enforce hard force or rail constraints. A large tilt or saturated force can invalidate the local design prediction.
Check your understanding+
Does a larger Q entry always mean a better real cart-pole run?
No. It changes the linear design preference; results also depend on state scales, other weights, model error and physical constraints.Why the next lesson follows
LQR still needs state information. A Kalman filter uses uncertainty estimates to decide how much to trust a model prediction and a noisy measurement.