LQR Control — Optimal Feedback vs Manual Gain Tuning

Manual PD tuning asks which gains appear stable. LQR asks a deeper engineering question: which feedback gains minimize a defined cost involving pointing error, angular-rate motion, and control effort?

Problem Setup

Attitude Stabilization as a Feedback Design Problem

Consider a simplified single-axis spacecraft attitude model. The spacecraft must rotate from an initial attitude error toward a commanded attitude while avoiding excessive angular velocity and excessive control torque.

$$ \dot{\theta} = \omega $$ $$ \dot{\omega} = u $$

Here, \( \theta \) is attitude angle, \( \omega \) is angular velocity, and \( u \) is the applied control torque. This is the same physical model used in many introductory attitude-control problems, but now the focus is not only stability. The focus is how the feedback gain should be chosen.

PD asks: “What gains feel stable?”
LQR asks: “What gains minimize a defined cost?”
Manual Tuning

Why Manual Tuning Becomes Hard

A manually tuned PD controller can work well for simple cases. Increasing \(K_p\) usually makes the response faster, while increasing \(K_d\) usually adds damping.

$$ u = K_p(\theta_{target}-\theta) - K_d\omega $$

The difficulty is that gain tuning is a tradeoff. A large \(K_p\) can reduce pointing error quickly, but it may demand more torque and excite oscillation. A large \(K_d\) can damp motion, but it can also slow the response or require high control effort.

State-Space Model

Writing the Attitude Model in State-Space Form

Define the state vector as:

$$ x = \begin{bmatrix} \theta \\ \omega \end{bmatrix} $$

The simplified attitude dynamics can be written as:

$$ \dot{x} = Ax + Bu $$
$$ A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}, \qquad B = \begin{bmatrix} 0 \\ 1 \end{bmatrix} $$

This form is powerful because it allows the controller to be written as direct feedback from the system state.

PD as State Feedback

PD Control Is Already a State Feedback Controller

For regulation toward zero attitude error, the PD controller can be written as:

$$ u = -Kx $$
$$ K = \begin{bmatrix} K_p & K_d \end{bmatrix} $$

This means PD and LQR use the same basic feedback structure. The difference is how \(K_p\) and \(K_d\) are chosen.

LQR Cost Function

What LQR Minimizes

LQR chooses a feedback gain by minimizing a quadratic cost:

$$ J = \int_0^\infty \left(x^TQx + u^TRu\right)dt $$

For the single-axis attitude model:

$$ Q = \begin{bmatrix} Q_\theta & 0 \\ 0 & Q_\omega \end{bmatrix}, \qquad R = [R] $$
\(Q_\theta\)

Penalizes attitude pointing error.

\(Q_\omega\)

Penalizes angular-rate motion.

\(R\)

Penalizes control torque effort.

Optimal Gain

How LQR Chooses Gains

LQR computes:

$$ K = R^{-1}B^TP $$

where \(P\) comes from the algebraic Riccati equation:

$$ A^TP + PA - PBR^{-1}B^TP + Q = 0 $$

In the interactive demo below, the model is the simple double-integrator attitude system, so the LQR gain can be computed directly from \(Q_\theta\), \(Q_\omega\), and \(R\).

Interactive Demo

Manual PD vs LQR Control

Adjust the manual PD gains and the LQR weights. The plot compares the manual response against the LQR response using the same initial attitude error. The cost breakdown shows what each design is paying for: attitude error, angular-rate motion, and control effort.

Manual PD tuning:





LQR weighting:







Constraint awareness:


Constraint Awareness: Ideal vs Saturated LQR

This plot compares the ideal LQR torque demand with the torque that a real actuator can actually deliver after saturation.

Manual PD Gain

Waiting for simulation...

LQR Gain

Waiting for simulation...

Cost Comparison

Waiting for simulation...

Engineering Interpretation

What the Comparison Shows

The LQR result is not automatically “better” in every practical sense. It is optimal for the model and cost function that were chosen. If the cost function penalizes torque strongly, LQR will choose a more conservative response. If pointing error is heavily penalized, it will become more aggressive.

LQR is only as meaningful as the model and cost function used to design it.

This is the main engineering lesson. Manual tuning gives intuition. LQR gives a systematic way to formalize tradeoffs. A strong control engineer understands both.

Takeaway

What This Problem Shows

Manual PD

Useful for intuition and quick tuning, but depends strongly on trial-and-error.

LQR

Computes gains by minimizing a cost that balances state error and control effort.

Engineering Tradeoff

The best controller depends on what the mission values: accuracy, smoothness, or torque economy.

The core lesson is:

Optimal control does not remove engineering judgement — it makes the judgement explicit.