先记住一句话
LQR 不是“自动调 PID”,而是给定完整 state model 与 Q/R 权重后,求让无限或有限时域累计 cost 最小的反馈矩阵。
1. 离散有限时域问题
xₖ₊₁=Axₖ+BuₖJ=x_NᵀQ_f x_N + Σₖ(xₖᵀQxₖ+uₖᵀRuₖ)Q⪰0 惩罚 state 偏差,R≻0 惩罚 control effort。单位不同,权重数值不能直接比;可先按允许最大偏差做 scaling(Bryson-style intuition)。
2. 为什么最优 policy 是线性的
若下一步 cost-to-go 为 Vₖ₊₁(x)=xᵀPₖ₊₁x,把 dynamics 代入 stage cost,对 u 求极小仍是 quadratic problem,得到:
uₖ*=−KₖxₖKₖ=(R+BᵀPₖ₊₁B)⁻¹BᵀPₖ₊₁APₖ 由 backward Riccati recursion 得到。无限时域 time-invariant 情况收敛到 algebraic Riccati solution,K 固定,可在 runtime 只做一次 matrix-vector multiply。
3. Q/R 怎样影响行为
- 提高某个 state 的 Q:更努力压制该方向误差;
- 提高某个 input 的 R:更少使用该 actuator;
- cross term 可表达 state/input coupling,但需保证整体 cost 合理;
- 统一放大 Q 和 R 不改变理想 LQR 的 K,只改变 cost scale。
结果仍受 controllability、model scaling 和 actuator limit 约束。大 Q 不会创造不存在的 torque。
4. Regulation 到 trajectory tracking
给 nominal x̄ₖ,ūₖ,定义偏差 δx=x−x̄, δu=u−ū,沿 trajectory linearize 得 δxₖ₊₁=Aₖδxₖ+Bₖδuₖ,然后 finite-horizon LQR:
uₖ = ūₖ − Kₖ(xₖ−x̄ₖ)ū 是 feedforward,−Kδx 是 feedback。只播放 optimal trajectory 而没有 feedback,会被微小 disturbance 推离。
5. Constraint 是 LQR 的硬边界
LQR 假设 input/state unconstrained。command 超 torque limit 后,真实 closed-loop 不再是 A−BK;joint limit、friction cone 和 collision 更无法靠 quadratic penalty 保证。小误差局部稳定可用 LQR,大范围带硬 constraint 通常进入 MPC。
6. LQG 与 separation principle
linear-Gaussian 条件下,用 Kalman filter 得 x̂,再施加 LQR u=−Kx̂,称 LQG。controller 与 estimator 可分别设计,closed-loop stability 有 separation principle。但 LQG 的 robustness 不自动由二者各自最优保证,model uncertainty/delay 仍需检查。
7. iLQR 与 DDP
对 nonlinear dynamics/非 quadratic cost,围绕 nominal trajectory 做局部 quadratic approximation,backward pass 求 local feedback/feedforward,forward rollout + line search 更新 trajectory。iLQR 常忽略 dynamics 二阶导数,DDP 保留更多二阶项。二者是 local nonconvex optimizer,initialization 和 contact nonsmoothness 很关键。
8. LQR、iLQR 与 MPC
| 方法 | runtime | constraint |
|---|---|---|
| Infinite LQR | offline Riccati,online −Kx | 无硬 constraint |
| TVLQR | offline/周期求 K_t | 无硬 constraint |
| iLQR/DDP | 迭代优化 nonlinear trajectory | 原生处理硬 constraint 较困难 |
| MPC | 每个 control tick 重解 finite-horizon problem | 核心优势之一 |
9. 四个可手算的 LQR 例子
例 1:先算一拍 stage cost
Scalar state x=2、input u=−1,取 Q=3,R=0.5:x²Q+u²R=4×3+1×0.5=12.5。这不是 loss 的“百分数”,而是设计权重下的相对代价。
例 2:一拍最优 feedback
x_next=x+u,cost 为 x_next²+u²。若 x=2,则 (2+u)²+u²=4+4u+2u²;令导数 4+4u=0,得 u*=−1,因此这一拍的 gain K=0.5。
例 3:trajectory error
实际 state [position,velocity]=[1.2,0.1],reference=[1.0,0],所以 δx=[0.2,0.1]。若 K=[4,1],则 δu=−(4×0.2+1×0.1)=−0.9。
例 4:Q/R 会改变选择
候选 A 让 state error=0.2、input=2;候选 B 为 error=0.8、input=0.5。当 Q=10,R=1 时,A cost=0.4+4=4.4,B=6.4+0.25=6.65,选 A;当 R=5 时,A=20.4,B=7.65,反而选 B。
LQR 中的“optimal”只相对于给定 linear model、quadratic objective 和无 constraint 假设。Q/R 选错、model range 超出或 actuator saturation 后,数学最优不等于真实机器人最好。
自测
1. 为什么 trajectory tracking 需要 feedforward 和 feedback?
feedforward 产生 nominal motion 所需 input,feedback 修正真实 state 相对 nominal 的偏差。
2. LQR 为什么 online 很便宜?
无限时域 gain 可 offline 解好,runtime 只需用当前 state 做 u=−Kx。
3. MPC 相对 LQR 最直接增加什么?
在有限 horizon 内显式处理 state/input 等 constraints,并随当前 state 反复重优化。
一手资料
MIT Underactuated Robotics 的 LQR 章节推导 finite/infinite horizon Riccati solution、trajectory stabilization,并连接 constrained LQR 与 MPC。