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.
First, 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.
What the model says
For a specified linear model ẋ=Ax+Bu, LQR minimizes an integral of xᵀQx+uᵀRu and produces u=−Kx under its assumptions. Q penalizes selected state deviations; positive R penalizes input use. The state coordinates have different units, so raw Q numbers are not directly comparable without scales. In the cart-pole Lab, the resulting gain acts on nonlinear dynamics with finite force and a rail limit; textbook optimality does not cover those violations.
J=∫₀∞(xᵀQx+uᵀRu)dt; u=−KxThe gain K is computed for a stated operating point, model and Q/R—not guessed by treating each matrix entry as a PID gain.
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.
Make it concrete
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.