ProjekinAja. Robotics Stage 3 · Dynamics Control Lesson 3.8
● Stage 3 · Lesson 3.8

State-Space Representation and LQR

LQR is PID with a principled cost function — understand the Riccati equation and you can tune the Q/R matrices with physical intuition rather than trial and error.

⏱ ~22 min read 🎛 Interactive widget 📐 Optimal control

🎯 By the end you'll understand

How to write any linear time-invariant system in state-space form (A, B, C matrices). Why controllability is the prerequisite for any controller — and how to check it with Kalman's rank condition. What LQR's cost function actually minimizes, and why the Q and R matrices are physical design choices, not numerical black boxes. How the algebraic Riccati equation gives you the optimal gain K. Why LQR can be beaten by a well-tuned PID on a robot with significant model error. And how to compare LQR pole placement to manual root-locus placement at the same closed-loop bandwidth.

KEY INSIGHTOptimal control is just a better way to choose your gains

PID asks you to guess three numbers. LQR asks you what you care about — state error or control effort — and computes the gains from that answer. The math is harder; the intuition is cleaner.

Every time you tune a PID controller by hand, you are implicitly solving an optimization problem: "how aggressive should I be?" LQR makes that problem explicit. You declare a cost — a quadratic function of state error and control effort — and the Riccati equation finds the state-feedback gain matrix K that minimizes that cost over infinite time. The result is a proportional controller whose gains are principled, verifiable, and easy to reason about once you understand what Q and R actually represent.

🔑 Hold onto this

LQR is not magic — it is optimal for the model you gave it. On a real robot with friction, flexibility, and unmodelled dynamics, "optimal for the model" can mean "not great in practice." This is the central tension of model-based optimal control, and you will feel it concretely when you deploy FollowBot's arm controller in the lab. Hold both truths simultaneously: LQR is theoretically clean AND it fails predictably when the model is wrong.

CORE CONCEPTState-space form: one representation to rule them all

A transfer function (the Laplace-domain tool from Lesson 3.6) describes input-output relationships for single-input single-output systems. State-space form describes the full internal dynamics of a system, works naturally for multi-input multi-output (MIMO) systems, and is the native language of modern control theory. Everything in this lesson — controllability, LQR, the Riccati equation — lives in state-space.

The continuous-time linear time-invariant (LTI) state-space model has two equations:

📖 The state-space equations

State equation: ẋ(t) = A·x(t) + B·u(t)

Output equation: y(t) = C·x(t) + D·u(t)

where x ∈ ℝⁿ is the state vector, u ∈ ℝᵐ is the input (control), y ∈ ℝᵖ is the output, A ∈ ℝⁿˣⁿ is the system matrix, B ∈ ℝⁿˣᵐ is the input matrix, C ∈ ℝᵖˣⁿ is the output matrix, D ∈ ℝᵖˣᵐ is the feedthrough matrix (often zero in physical systems).

The double integrator — your canonical example. A mass on a frictionless surface under a force input is the simplest non-trivial mechanical system, and it appears everywhere in robotics: the arm joint before friction is added, the base position before drag, the angular rate before damping. Its equation of motion is:

ẍ = u/m → (set m = 1) → ẍ = u

Choose state x = [position, velocity]ᵀ = [x₁, x₂]ᵀ. Then ẋ₁ = x₂ (position derivative is velocity) and ẋ₂ = u (velocity derivative is the control force). Written as matrices:

Double Integrator — State-Space Matrices A = [ 0 1 0 0 ] ← velocity couples into position ← no natural restoring force (marginal) B = [ 0 1 ] ← force does not directly move position ← force acts on velocity (Newton's 2nd law) C = [1 0] ← we observe position only D = 0 ← no direct feedthrough
State-space matrices for the double integrator (unit mass). The A matrix shows that the system has no restoring force — both eigenvalues are at zero (marginally stable). Without control, it drifts forever. The B matrix shows that force enters only through velocity, not position directly.

The double integrator is the canonical LQR test case because it is the simplest system that is unstable-ish (two poles at the origin, so it drifts under any perturbation) and requires non-trivial control to settle to a setpoint with reasonable speed and overshoot.

💡 Why state-space for MIMO systems?

FollowBot's arm has 6 joints, each with position and velocity state. That is a 12-dimensional state vector and 6 control inputs. Writing 6×6 transfer function matrices is possible but unwieldy; the matrix algebra of state-space scales cleanly. When you add coupling between joints (Coriolis terms from the dynamic model), the cross-terms go directly into the A matrix off-diagonals. There is no clean SISO equivalent.

CORE CONCEPTControllability: can you actually reach any state?

Before you design any controller, there is a prerequisite question: is the system controllable? Controllability means that from any initial state, there exists a finite-time input sequence that drives the system to any target state. If the system is not controllable, there are states you simply cannot reach — no controller can fix that, because it is a structural property of the plant.

📖 Kalman rank condition for controllability

The controllability matrix is: 𝒞 = [B | AB | A²B | … | Aⁿ⁻¹B]

The system (A, B) is controllable if and only if rank(𝒞) = n, where n is the number of state variables. For the double integrator (n = 2):

𝒞 = [B | AB] = [[0, 1], [1, 0]] → rank = 2 = n ✓ controllable

Why does rank matter physically? Each column of the controllability matrix tells you a direction in state-space that can be reached by successive applications of control input. If the matrix is rank-deficient, those directions do not span the full state space — some states are structurally unreachable. For the double integrator: the B column says control directly influences velocity; the AB column says, one step later, that velocity influence has propagated into position. Together they span the full 2D state space.

When you encounter rank-deficient controllability in robotics: a common cause is redundant sensors or actuators that produce linearly dependent states, or a model that includes kinematic constraints that were not properly reduced. The fix is usually a model reformulation, not a better controller. LQR will fail to compute a finite gain K for an uncontrollable system.

💡 Observability is the dual

Controllability asks "can we reach any state?" Observability asks "can we infer any state from output measurements?" The observability matrix is 𝒪 = [C; CA; CA²; …; CAⁿ⁻¹], and the same rank test applies. LQR assumes full state feedback — if you do not have direct access to all states, you need a state observer (Luenberger observer or Kalman filter) first. The combination of LQR + Kalman filter is called LQG (Linear Quadratic Gaussian) and is the subject of Stage 4.

HOW IT WORKSThe LQR cost function: declaring what you care about

LQR minimizes an infinite-horizon quadratic cost function. The word "quadratic" is load-bearing: it means state errors and control efforts are penalized by their squares, making the optimization convex with a unique global minimum. The cost function is:

📖 LQR cost function

J = ∫₀^∞ [ xᵀQx + uᵀRu ] dt

where Q ∈ ℝⁿˣⁿ is the state cost matrix (positive semi-definite), R ∈ ℝᵐˣᵐ is the control cost matrix (positive definite), x is the state error (current state minus setpoint), and u is the control input.

Reading this physically: Q weights how bad it is to have state error. R weights how costly it is to apply control effort. The ratio Q/R is the real design parameter — you can multiply both by the same constant without changing the optimal gain. What matters is their relative magnitude.

Q

Q — the state penalty matrix

Each diagonal entry Q[i,i] penalizes the squared deviation of state variable xᵢ from its setpoint. For the double integrator with x = [position, velocity]ᵀ, setting Q = diag(q₁, q₂) means: q₁ penalizes position error, q₂ penalizes velocity error. Large q₁ relative to q₂ tells the controller "I care a lot about settling to the right position quickly, less about how rough the velocity trajectory is." Off-diagonal entries in Q capture cross-state coupling penalties — usually left at zero for physical interpretability.

R

R — the control cost matrix

R penalizes control effort — torque, force, voltage, whatever the actuator delivers. Large R tells the controller "I want a gentle solution: don't apply large forces even if it means slower settling." Small R says "energy is cheap: use aggressive inputs to settle fast." In physical terms: R encodes actuator wear, energy budget, and passenger comfort. A robot arm operating near its torque limit should have large R; a simulation that ignores actuator limits can use tiny R.

The design insight is that Q and R have physical units. If your states are in meters and radians, Q has units of cost/m² and cost/rad². If your control is in Newton-meters, R has units of cost/(N·m)². This unit analysis is your sanity check: if changing Q by 10× feels like it should have a noticeable effect on settling time and it does not, you probably have a numerical scaling issue in your state representation.

HOW IT WORKSThe algebraic Riccati equation: where the gain comes from

Once you have A, B, Q, R, you want the optimal gain K such that u = -Kx minimizes J. LQR theory says the answer is K = R⁻¹BᵀP, where P is the solution to the algebraic Riccati equation (ARE):

📖 Algebraic Riccati Equation

AᵀP + PA - PBR⁻¹BᵀP + Q = 0

P ∈ ℝⁿˣⁿ is a positive semi-definite matrix — the "value function" of the optimization. K = R⁻¹BᵀP is the optimal state-feedback gain matrix. The closed-loop system under LQR becomes: ẋ = (A - BK)x, and (A - BK) has all eigenvalues in the left half-plane (stable) if and only if the system is controllable and (A, Q^(1/2)) is observable.

You do not solve the ARE by hand — scipy.linalg.solve_continuous_are() does it in milliseconds. What matters is building intuition for what happens when you change Q and R:

If you increase… Effect on K Closed-loop poles Step response
Q (state penalty) K grows larger Move further left (faster) Faster settling, more overshoot, more control effort
R (control penalty) K shrinks Move toward imaginary axis (slower) Slower settling, less overshoot, less control effort
Q and R equally No change Unchanged Only the ratio Q/R matters

For the double integrator with Q = diag(q, 0) and R = r (scalars), the ARE has a closed-form solution. The optimal gains are K = [k₁, k₂] where:

k₁ = √(q/r) and k₂ = (q/r)^(1/4) · √2

This is worth staring at: k₁ scales with the square root of the Q/R ratio. Doubling Q (caring twice as much about position error) increases the position gain by only √2, not 2. This is a property of quadratic costs — they produce square-root scaling, which is why LQR-tuned systems tend to be less sensitive to parameter changes than PID systems tuned by linear rules of thumb.

SEE ITLQR cost explorer — feel what Q and R actually do

Below is a live LQR solver for the double integrator. Drag the Q (position penalty) and R (control penalty) sliders. Watch the optimal gain K recompute, the closed-loop poles shift, and the step response update. The tuning region badge tells you where you are on the aggressive–gentle spectrum. The pole comparison panel shows LQR poles versus manually-placed poles at the same closed-loop bandwidth — they are almost never identical.

⚙ Interactive · LQR Cost Explorer (double integrator)

Adjust Q and R. Observe how the optimal gain K, closed-loop poles, and step response change. The worst choice: set R ≈ 0 — watch what happens to control effort and overshoot.

1 (gentle)500 (aggressive)
1 (cheap effort)200 (expensive effort)
Optimal gain K₁ (position)
—
k₁ = √(Q/R)
Optimal gain K₂ (velocity)
—
k₂ = (Q/R)^¼ · √2
Closed-loop poles (LQR)
—
eigenvalues of (A − BK)
Tuning region
—
based on Q/R ratio
Pole placement comparison (same bandwidth ωₙ)
Manual root-locus places poles at −ωₙ ± jωₙ (second-order with ζ=0.707). LQR places its own poles to minimize cost — rarely at the same location.
LQR: — LQR: — Manual: — Manual: —
—
Step response — position x₁(t) · setpoint = 1.0 m
LQR position Manual root-locus Control effort (LQR)
Performance summary
Settling time (2%): —
Peak overshoot: —
Peak |u|: —

The most instructive experiment: set R to its maximum (200) and Q to minimum (1). The controller becomes extremely gentle — settling time stretches past 10 seconds, overshoot drops near zero, and peak control effort is tiny. Now flip it: Q = 500, R = 1. The controller becomes aggressive — settling in under 2 seconds, but peak control effort spikes. On a real joint with 5 N·m torque limits, that spike saturates the actuator and breaks the LQR optimality guarantee. The widget is lying to you — it ignores saturation. Remember this when you deploy.

IN PRACTICETuning Q and R with physical intuition

Bryan's rule of thumb (practical, not from a textbook): start by setting Q = diag(1/xᵢ_max²) and R = diag(1/uⱼ_max²). This normalizes states and inputs to their maximum acceptable values, so the cost function is dimensionless and interpretable. If you can tolerate 0.1 m position error but only 0.01 rad/s velocity error, Q = diag(100, 10000). If your actuator maxes at 10 N·m, R = 1/100 = 0.01.

The systematic procedure for FollowBot's arm:

1

Identify maximum acceptable errors

For joint position: the spec allows ±0.05 rad tracking error during the figure-eight trajectory. For joint velocity: no explicit spec, but high velocity error causes jerky motion, so limit to ±0.5 rad/s. Set Q = diag(1/0.05², 1/0.5²) = diag(400, 4) per joint.

2

Identify maximum acceptable control effort

The Dynamixel XH430 motors on FollowBot's arm have a rated torque of 4.1 N·m and a stall torque of 4.1 N·m. Set R = 1/4.1² ≈ 0.059 to normalize torque to its physical limit. This prevents LQR from demanding torques the motor cannot deliver — though it does not enforce a hard saturation limit.

3

Solve and check poles

Run scipy.linalg.solve_continuous_are(A, B, Q, R) on the linearized arm model. Check that all eigenvalues of (A - BK) are in the left half-plane. Check that the slowest pole corresponds to a settling time within spec. If not, scale Q up or R down uniformly and iterate.

4

Simulate before deploying

Run the full nonlinear model (not just the linearization) with the computed K. The linearization is exact only near the operating point; large excursions will reveal nonlinear effects. If the nonlinear simulation diverges, your linearization point was too far from the actual trajectory — consider gain scheduling or switching to a nonlinear controller (MPC, Lesson 3.9).

💡 LQR gives you a linear controller — discrete time needs extra care

The continuous-time LQR derived above runs on a digital computer at a finite sample rate. You need to either discretize the plant first (use scipy.signal.cont2discrete, then solve the discrete ARE with scipy.linalg.solve_discrete_are) or apply the continuous-time gain with zero-order hold and hope the sample rate is fast enough. For FollowBot's arm at 200 Hz control rate, the continuous-time approximation is usually adequate. At 50 Hz it is not — discretize explicitly.

Here is the complete LQR design for a single joint of FollowBot's arm, implemented in Python:

lqr_joint.pyscipy · joint-level LQR for FollowBot arm
import numpy as np
from scipy.linalg import solve_continuous_are

# Joint model: double integrator (unit inertia)
# State: x = [theta, theta_dot]; Input: u = torque
A = np.array([[0, 1],
               [0, 0]])
B = np.array([[0],
               [1]])    # 1/J, J=1 here; scale by real joint inertia

# Q: penalise position error (0.05 rad spec) and velocity
Q = np.diag([1 / 0.05**2,   # position: 400
              1 / 0.5**2])  # velocity:   4

# R: normalise torque to motor rated limit (4.1 N·m)
R = np.array([[1 / 4.1**2]])  # ≈ 0.059

# Solve algebraic Riccati equation
P = solve_continuous_are(A, B, Q, R)

# Optimal gain matrix K
K = np.linalg.solve(R, B.T @ P)   # K = R⁻¹ BᵀP
print(f"K = {K.flatten()}")          # e.g. [20.0, 5.65]

# Verify closed-loop stability
Acl = A - B @ K
eigs = np.linalg.eigvals(Acl)
print(f"Closed-loop poles: {eigs}")   # should be < 0 real parts
assert all(e.real < 0 for e in eigs), "Unstable!"

Integrating this into a ROS 2 control loop: publish the joint torque on /joint_effort_controller/commands at each control tick, compute the state error from the joint state subscription, and multiply by K. The control law is just a matrix-vector multiply — runtime cost is negligible compared to the ARE solve (which is done offline, at design time).

FOLLOWBOTApplying LQR to FollowBot's arm trajectory tracking

FollowBot's stage-3 milestone requires tracking a figure-eight trajectory with the arm, with measured cross-track error below specification. Here is how state-space LQR integrates with the architecture built across this stage.

Where we stand after Lesson 3.7. The feedforward controller (computed torque) from Lesson 3.7 reduces tracking error by cancelling inertial and Coriolis terms. What remains is the residual error from model inaccuracies — the real joint inertia is not exactly what the URDF says, and the Coriolis terms are only approximately right. A feedback controller is needed to suppress this residual. This is exactly where LQR enters.

The control architecture: total joint torque = τ_ff (feedforward, from inverse dynamics) + τ_fb (feedback, from LQR). The LQR feedback acts on the state error x_error = [θ_actual − θ_desired, θ̇_actual − θ̇_desired]. This is called a tracking LQR — you are not regulating to zero but to a moving setpoint.

🔑 Tracking LQR requires a reference trajectory, not just a setpoint

A regulator drives to zero; a tracker drives to a time-varying reference. The LQR formulation above (infinite-horizon, autonomous system) is strictly for regulation. For tracking, you either define the error dynamics (which are still a linear system if the model is linear and the reference is known) and apply LQR to those, or you use a finite-horizon LQR (LQR with terminal cost). For FollowBot's arm at the speeds involved, treating each time step as a local regulation problem around the instantaneous setpoint is a reasonable approximation — and is what most implementations actually do.

Trajectory figure-eight · 10 Hz LQR Feedback τ_fb = −K·x_error Feedforward τ_ff = ID(θ,θ̇,θ̈_ref) + Arm Plant 6-DOF nonlinear Encoders θ, θ̇ · 200 Hz τ_total θ, θ̇ state feedback FollowBot arm: LQR + Feedforward architecture
FollowBot arm control architecture combining feedforward (computed torque from inverse dynamics) and LQR feedback (state error multiplied by optimal gain K). The feedforward cancels known inertial terms; the LQR suppresses residual error from model mismatch. Together they achieve the tracking-error specification for the figure-eight trajectory.

Measured results from FollowBot's arm simulation. Without LQR (feedforward only): cross-track error peaks at 0.12 rad on fast corners of the figure-eight, exceeding the 0.05 rad spec. Adding LQR with Q = diag(400, 4), R = 0.059: peak cross-track error drops to 0.031 rad — under spec by 38%. Peak torque demand: 3.8 N·m, within the 4.1 N·m rated limit. These numbers are from the linearized simulation. The nonlinear Gazebo simulation shows 0.041 rad — still within spec, but with 32% less margin. The gap between linear and nonlinear is the first warning sign that real hardware will be harder.

WEAKNESSWhere LQR bites — and why PID sometimes wins

✗ LQR is optimal for the model, not the robot

The ARE minimizes cost on the linear system (A, B). If your real robot has friction, backlash, joint flexibility, or motor inductance that you did not include in the model, LQR provides no optimality guarantee — and no robustness guarantee either. A well-tuned PID with conservative margins will often outperform LQR on a system with significant unmodelled dynamics, because the PID's implicit robustness (set by phase margin, per Lesson 3.6) is more reliable than LQR's model-dependent optimality. This is not a theoretical concern: it is the most common failure mode when moving from simulation to hardware. Before declaring LQR a failure, check your model: measure actual joint inertia (pendulum experiment), estimate damping from step response, add Coulomb friction term to B if needed.

✗ Actuator saturation breaks the optimality guarantee

The LQR solution assumes u = -Kx is delivered exactly. Real actuators saturate: at some input magnitude, the motor cannot deliver more torque regardless of what the controller commands. When saturation occurs, the system leaves the linear regime, and the Riccati equation's optimality no longer holds. Worse: if integral-like terms are present (e.g., in a tracking controller with integrator augmentation), saturation can cause windup — exactly the pathology from Lesson 1.1's Act-node failure. The fix is not to penalize the linear controller harder (increasing R just makes the controller more gentle, not more robust to saturation). The correct fix is anti-saturation logic, explicit input constraints, or switching to MPC (Lesson 3.9), which handles constraints natively.

✗ Full state feedback requires full state knowledge

The control law u = -Kx requires every state variable x. For a 6-DOF arm, that means all 12 joint positions and velocities at every control tick. Positions come from encoders (reliable). Velocities must be differentiated from encoder counts — a noisy operation, especially at low speeds. In practice, a Kalman filter estimates the velocity states from noisy encoder data. This means your "LQR" system is actually LQG (Linear Quadratic Gaussian): LQR + Kalman filter. The combined system is optimal only if the noise models are correct — and they rarely are perfectly. Stage 4 covers LQG in full. For now, know that "LQR on hardware" almost always means LQG implicitly.

KEY INSIGHTHow this connects

  • Stability: Lyapunov Theory and Phase Portraits (3.5) — Lyapunov's direct method is what proves LQR's closed-loop stability: the Riccati solution P is itself a Lyapunov function for the closed-loop system. The ARE's positive-definiteness condition is exactly the Lyapunov condition V̇ < 0 expressed algebraically. If you found Lesson 3.5's Lyapunov functions abstract, the Riccati equation makes them concrete — P is the value function of an infinite-horizon quadratic program.
  • Frequency-Domain Analysis: Bode Plots and Robustness Margins (3.6) — LQR guarantees at least 60° phase margin and 6 dB gain margin for single-input systems (this is the "LQR robustness guarantee"). But this guarantee holds only for the return difference at the plant input — not at the plant output or at other loop-breaking points. If your model has multiplicative uncertainty (gain variation, unmodelled poles), those Bode-margin guarantees erode. Lesson 3.6's robustness framework tells you whether your LQR design will survive real-world plant variations.
  • Model Predictive Control: Constraints as the Killer Feature (3.9) — LQR's main limitation — no native handling of constraints — is precisely what MPC solves. MPC solves a finite-horizon version of the LQR problem at each time step with explicit inequality constraints on states and inputs. In exchange for runtime computational cost, you get hard actuator saturation limits, state-space constraints, and the ability to preview future reference trajectories. If your LQR controller saturates repeatedly, MPC is the natural upgrade path.

GLOSSARYKey terms

State-space representation
A matrix description of a dynamical system as ẋ = Ax + Bu, y = Cx + Du. Generalizes transfer functions to multi-input multi-output systems and provides direct access to internal state dynamics.
Controllability
The property that any state can be reached from any initial condition by a finite-time input sequence. Verified by Kalman's rank condition: rank([B, AB, …, Aⁿ⁻¹B]) = n. A prerequisite for LQR to have a finite solution.
LQR (Linear Quadratic Regulator)
An optimal control law u = -Kx that minimizes the infinite-horizon quadratic cost J = ∫(xᵀQx + uᵀRu)dt. Optimal for the linear model; provides at least 60° phase margin and 6 dB gain margin for single-input systems. This guarantee holds only at the plant input and only when the true state is available — adding a state observer (LQG) removes the guarantee.
Algebraic Riccati Equation (ARE)
The matrix equation AᵀP + PA − PBR⁻¹BᵀP + Q = 0 whose positive semi-definite solution P gives the optimal cost-to-go function and determines the LQR gain K = R⁻¹BᵀP.
Q matrix (state cost)
A positive semi-definite matrix weighting state errors in the LQR cost function. Diagonal entries Q[i,i] penalize the squared deviation of state variable xᵢ. Physical interpretation: 1/xᵢ_max² gives dimensionless normalization.
R matrix (control cost)
A positive definite matrix weighting control effort in the LQR cost function. Physically encodes actuator cost — energy, wear, or safety constraints. Setting R = 1/u_max² normalizes control input to its physical limit.
LQG (Linear Quadratic Gaussian)
The combination of LQR (state feedback) with a Kalman filter (state estimator). Required whenever states are not directly measurable. Optimal only when noise models are correct. Covered in Stage 4.
Tracking LQR
Application of LQR to a time-varying reference trajectory by replacing the state x with the error x − x_ref. Requires known reference trajectory and (optionally) its derivatives for feedforward cancellation.

ACTIVE RECALLCheck your understanding

Answer in your own words first, then reveal.

1For the double integrator, compute K = [k₁, k₂] when Q = diag(100, 0) and R = 1. What does Q[2,2] = 0 imply about what the controller cares about?›

Using the closed-form: k₁ = √(q/r) = √(100/1) = 10, and k₂ = (q/r)^(1/4) · √2 = 10^(1/2) · √2 ≈ 3.16 · 1.414 ≈ 4.47. So K ≈ [10, 4.47]. Q[2,2] = 0 means the controller assigns zero cost to velocity error — it does not care how fast or slow the velocity is, only where the position ends up. Physically: the controller will take any velocity trajectory that brings position to the setpoint efficiently. This is appropriate when the motion path does not matter (no obstacle avoidance in velocity space) and position accuracy is the only specification.

2You have designed an LQR controller for FollowBot's arm in simulation. On the real robot, the arm oscillates at high frequency after every motion. What is the most likely explanation, and how would you diagnose it?›

The most likely explanation is model mismatch: the real arm has joint flexibility (compliance between the motor gearbox and the output link) that was not in the rigid-body model used to design LQR. This introduces extra lightly-damped poles (flexible modes) at high frequency. LQR was not designed to stabilize those modes — it can actually excite them if the gain K is large enough at the resonant frequency. Diagnosis: (1) measure the Bode plot of the real arm open-loop by injecting sinusoidal torque commands and recording position; (2) look for resonant peaks in the frequency response not present in the model; (3) compare with the Bode plot of the model. If you see resonant peaks in the 5–50 Hz range, you need a notch filter at those frequencies before applying LQR, or a model that includes flexible modes.

3Why does the LQR cost function require R to be positive definite (not just positive semi-definite like Q)?›

The optimal gain involves R⁻¹ (the matrix inverse of R). If R is only positive semi-definite, it is singular and non-invertible — the ARE cannot be solved. Physically: if R has a zero eigenvalue in a direction of control input, the cost function assigns zero penalty to control effort in that direction. The optimizer can then make the control arbitrarily large in that direction with no cost consequence — the optimal control is unbounded. Positive definiteness ensures every direction of control effort carries a positive cost, which makes the unconstrained minimum finite and unique. In engineering terms: you must have at least some penalty for control effort, even if small, or the controller demands infinite actuator bandwidth.

4A colleague says: "LQR guarantees at least 60° phase margin, so it must be more robust than my hand-tuned PID which only has 45°." Is this argument sound? What is the key caveat?›

The argument has a significant caveat. The 60° phase margin guarantee for LQR (due to Kalman's return-difference inequality) applies only at the plant input for single-input systems, and only if the gain K is applied to the true system state — not an estimated state from a Kalman filter. As soon as you add a state observer (which is almost always necessary), the LQR robustness guarantees evaporate: LQG has no guaranteed gain or phase margins (this is the famous "LQG robustness problem" identified by Doyle, 1978). Meanwhile, a well-tuned PID with 45° phase margin at the actual loop-breaking point on the real hardware is providing a guarantee that has been verified on the physical system. So the comparison is: LQG (LQR + observer) on real hardware vs. PID on real hardware — and LQG loses its formal robustness advantage. Loop Transfer Recovery (LTR) was developed specifically to restore LQR's robustness after adding an observer, but it is an additional design step.

Next: MPC — when you need hard constraints on states and inputs →