LQR Design (gnc-autonomy/optimal-control/lqr-design)
Use when the task is LQR state-feedback design for a scalar-input
two-state system: solving the Riccati equation, computing the gain
matrix, and verifying closed-loop stability.
Domain quick reference
- LQR minimizes the quadratic cost J = integral(x'Qx + u'Ru) over the
linear system x' = A x + B u; the optimal state feedback is u = -K x.
- The gain is K = R^-1 B' P with P the stabilizing solution of the
algebraic Riccati equation A'P + PA - P B R^-1 B' P + Q = 0.
- For the canonical scalar-input two-state form A = [[0,1],[0,-a]],
B = [0,1] (a damped double integrator), the Riccati equation reduces
to a small closed-form system solved directly from q1, q2, r, and a.
- A 2x2 closed-loop matrix A - B K is stable exactly when its trace is
negative and its determinant positive; the pole pair follows from the
quadratic formula.
- Q penalizes state error and R penalizes control effort; their ratio
sets the gain magnitude and the settling speed of the regulated
system.
- ARP4754A (reference-only) frames development assurance for aircraft
systems; the Riccati mathematics here is common control-theory
knowledge.
Workflow
- Put the plant in canonical form: A = [[0,1],[0,-a]] with damping
a >= 0, input B = [0,1], and pick cost weights Q = diag(q1, q2),
R = r in one consistent SI convention (for an attitude plant: q1 in
1/rad^2, q2 in 1/(rad/s)^2, r in 1/(N m)^2).
- Solve the Riccati equation with riccati_gain for the symmetric
matrix P.
- Compute the gain with gain_matrix: K = R^-1 B' P, returned as
[k1, k2].
- Verify the closed loop with closed_loop_stable: eigenvalues of
A - B K, reported as a stability verdict plus the pole pair.
- Assess the weights with cost_weight_guide and re-tune q1, q2, r
when the gains are too aggressive or too weak.
Pitfalls
- Iterating the Riccati equation with the policy-iteration map
P <- A'P + PA - P B R^-1 B' P + Q; that map is not a contraction and
need not converge. Solve the ARE directly instead.
- Applying the closed form outside the canonical family: a general A
and B need a general Riccati solver, not this leaf's equations.
- Mixing weight conventions (rad with deg, torque in N m with weights
scaled for a different unit); the gain and the closed-loop poles
change with the convention.
- Checking stability from the determinant alone; a 2x2 closed loop
needs trace < 0 AND determinant > 0.
- Accepting negative q or nonpositive r; the module raises ValueError
on impossible weights.
Behavior contract (gate 3)
The Riccati solve, gain computation, closed-loop stability verdict,
and cost-weight guidance are exercised by the gate 3 contract test:
scripts/test_lqr_design_logic.py against scripts/lqr_design_logic.py
(stdlib unittest, offline). Run:
python3 scripts/test_lqr_design_logic.py
Compliance
- ARP4754A is proprietary (SAE); name and paraphrase only per
standards-map.yaml, reference-only: true.
- compliance: STANDARDS-REF, gated: false.
1---2name: lqr-design3description: Use when you must design an LQR state-feedback gain matrix for a scalar-input two-state system such as spacecraft attitude control: solve the algebraic Riccati equation for the cost weights, compute the gain matrix, verify closed-loop stability of the regulated system, and assess the Q over R weighting trade. Produces the Riccati solution, the gain vector, and the stability verdict that feed the control-law design. Trigger: lqr, linear quadratic regulator, riccati equation, gain matrix, state feedback, closed loop stability, control effort, spacecraft attitude control.4license: Apache-2.05---67# LQR Design (gnc-autonomy/optimal-control/lqr-design)89Use when the task is LQR state-feedback design for a scalar-input10two-state system: solving the Riccati equation, computing the gain11matrix, and verifying closed-loop stability.1213## Domain quick reference1415- LQR minimizes the quadratic cost J = integral(x'Qx + u'Ru) over the16 linear system x' = A x + B u; the optimal state feedback is u = -K x.17- The gain is K = R^-1 B' P with P the stabilizing solution of the18 algebraic Riccati equation A'P + PA - P B R^-1 B' P + Q = 0.19- For the canonical scalar-input two-state form A = [[0,1],[0,-a]],20 B = [0,1] (a damped double integrator), the Riccati equation reduces21 to a small closed-form system solved directly from q1, q2, r, and a.22- A 2x2 closed-loop matrix A - B K is stable exactly when its trace is23 negative and its determinant positive; the pole pair follows from the24 quadratic formula.25- Q penalizes state error and R penalizes control effort; their ratio26 sets the gain magnitude and the settling speed of the regulated27 system.28- ARP4754A (reference-only) frames development assurance for aircraft29 systems; the Riccati mathematics here is common control-theory30 knowledge.3132## Workflow33341. Put the plant in canonical form: A = [[0,1],[0,-a]] with damping35 a >= 0, input B = [0,1], and pick cost weights Q = diag(q1, q2),36 R = r in one consistent SI convention (for an attitude plant: q1 in37 1/rad^2, q2 in 1/(rad/s)^2, r in 1/(N m)^2).382. Solve the Riccati equation with riccati_gain for the symmetric39 matrix P.403. Compute the gain with gain_matrix: K = R^-1 B' P, returned as41 [k1, k2].424. Verify the closed loop with closed_loop_stable: eigenvalues of43 A - B K, reported as a stability verdict plus the pole pair.445. Assess the weights with cost_weight_guide and re-tune q1, q2, r45 when the gains are too aggressive or too weak.4647## Pitfalls4849- Iterating the Riccati equation with the policy-iteration map50 P <- A'P + PA - P B R^-1 B' P + Q; that map is not a contraction and51 need not converge. Solve the ARE directly instead.52- Applying the closed form outside the canonical family: a general A53 and B need a general Riccati solver, not this leaf's equations.54- Mixing weight conventions (rad with deg, torque in N m with weights55 scaled for a different unit); the gain and the closed-loop poles56 change with the convention.57- Checking stability from the determinant alone; a 2x2 closed loop58 needs trace < 0 AND determinant > 0.59- Accepting negative q or nonpositive r; the module raises ValueError60 on impossible weights.6162## Behavior contract (gate 3)6364The Riccati solve, gain computation, closed-loop stability verdict,65and cost-weight guidance are exercised by the gate 3 contract test:66scripts/test_lqr_design_logic.py against scripts/lqr_design_logic.py67(stdlib unittest, offline). Run:68python3 scripts/test_lqr_design_logic.py6970## Compliance7172- ARP4754A is proprietary (SAE); name and paraphrase only per73 standards-map.yaml, reference-only: true.74- compliance: STANDARDS-REF, gated: false.