iLQR Control Method Tutorial
iLQR Control Method Tutorial
July 2, 2019
1 LQR Derivation
1.1 Discrete Case (Regulator)
xk+1 = Ak xt + Bk uk
N −1
1 T 1 X T
J(x0 , U ) = xN Qf xN + xk Qk xk + uTk Rk uk
2 2
k=1
Using the Principle of Optimality and Pontryagin’s Minimum Principle, we can compute the optimal cost-to-go
Vk (xk ) = 12 xk Sk xk by working backwards from the boundary condition/terminal cost.
1 T 1
VN (xN ) = x Qf xN = xTN SN xN
2 N 2
1 T 1
VN −1 (xN −1 ) = min xN −1 QN −1 xN −1 + uTN −1 RN −1 uN −1 + VN (xN )
uN −1 2 2
1 T 1 T
= min xN −1 QN −1 xN −1 + uN −1 RN −1 uN −1 + VN (AN −1 xN −1 + BN −1 uN −1 )
uN −1 2 2
1 T 1 T 1 T
= min xN −1 QN −1 xN −1 + uN −1 RN −1 uN −1 + AN −1 xN −1 + BN −1 uN −1 SN AN −1 xN −1 + BN −1 uN −1
uN −1 2 2 2
1 T 1 T
= min xN −1 QN −1 xN −1 + uN −1 RN −1 uN −1
uN −1 2 2
1 T T
+ xN −1 AN −1 SN AN −1 xN −1 + uTN −1 BN
T T T T T
−1 SN BN −1 uN −1 + xN −1 AN −1 SN BN −1 uN −1 + uN −1 BN −1 SN AN −1 x
2
(1)
Using Pontryagin’s Minimum Principle we can solve for the optimal control for a single time step uk , instead of the
entire control sequence U .
∂V T T
= RN −1 uN −1 + BN −1 SN BN −1 uN −1 + BN −1 SN AN −1 xN −1 = 0
∂u
(2)
u∗N −1 = −(RN −1 + BN
T
−1 SN BN −1 )
−1 T
BN −1 SN AN −1 xN −1
≡ KN −1 xN −1
The optimal control can be substituted back into the above equation to compute the optimal cost-to-go
1 T 1
VN −1 (xN −1 ) = x QN −1 xN −1 xTN −1 KNT
−1 RN −1 KN −1 xN −1
2 N −1 2
1 T
+ AN −1 xN −1 + BN −1 KN −1 xN −1 PN AN −1 xN −1 + BN −1 KN −1 xN −1
2
1 T T −1
= xN −1 QN −1 + KN R K
−1 N −1 N −1 + (A N −1 + B K
N −1 N −1 ) SN (A N −1 + B N −1 N −1 xN −1
K )
2
1
≡ xN −1 SN −1 xN −1
2
(3)
1
2 iLQR Derivation
We first start the derivation by setting up the problem by defining the dynamics, cost function, and cost-to-go
variable.
∂f ∂f
xk+1 + δxk+1 = f (xk + δxk , uk + δuk ) ≈ f (xk , uk ) + (x − xk ) + (u − uk )
∂x xk ,uk ∂u xk ,uk
δxk+1 = A(xk , uk )δxk + B(xk , uk )δuk (5)
(6)
∂f ∂f
where A ≡ ∂x and B ≡ ∂u .
For the we define a few variables of convenience (→ indicates equivalence for quadratic cost function):
∂`
`x ≡ → Qk xk + qk
∂x xk ,uk
∂`
`u ≡ → Rk uk + rk
∂u xk ,uk
∂2`
`xx ≡ → Qk
∂x2 xk ,uk
(8)
∂2`
`uu ≡ → Rk
∂u2 xk ,uk
∂2`
`xu ≡ → Hk
∂x∂u xk ,uk
∂2`
`ux ≡ → HkT
∂u∂x xk ,uk
With a given cost function, we can apply Bellman’s Principle of Optimality to define the optimal cost-to-go Vk (x)
by the recurrence relation:
VN = `f (xN )
Vk = min{`(xk , uk ) + Vk+1 (f (xk , uk ))} (9)
u
Vk = min Qk (xk , uk )
u
2
We approximate the cost-to-go function as locally quadtratic near the nominal trajectory:
∂V 1 ∂2V
Vk + δVk = Vk (xk + δxk ) ≈ V (xk ) + (x − xk ) + (x − xk )T (x − xk )
∂x xk 2 ∂x2 xk
(10)
1
δVk (xk ) = sTk xk + xTk Sk xk
2
Similarly:
T T
1 δxk Qxx Qxu δxk Qx δxk
δQk (xk , uk ) = +
2 δuk Qux Qxx δuk Qu δuk
Qx = `x + sk+1 Ak
Qu = `u + sk+1 Bk
Qxx = `xx + ATk Sk+1 Ak (11)
Quu = `uu + BkT Sk+1 Bk
Qux = `ux + BkT Sk+1 Ak
3
2.4 Solving the Dynamic Programming Problem
After solving the tail sub-problem, we can then apply the principle of optimality and define the process for solving
for the kth time step given the values at the k + 1th time step.
= min{Qk (xk , uk )}
uk
δV = min{δQ(x, u)}
δu
1 1 1 1
= min{Qx δx + Qu δu + δxT Qxx δx + δuT Quu δu + δxT Qxu δu + δuT Qux δx}
δu 2 2 2 2
∂δQ 1 1
= Qu + Qux δx + QTxu δx + Quu δu = 0
∂δu 2 2
→ δu∗ = −Q−1
uu (Qux δxk + Qu)
= Kδx + d
So
dk = −Q−1
uu Qu
Kk = −Q−1
uu Qux
After calculating the optimal control as a function of the next time step we can plug it back into Equation ??.
T T
1 δxk Qxx Qxu δxk Qx δxk
δQk (xk , uk ) = +
2 Kδx + d Q ux Qxx Kδx + d Qu Kδx + d
δx = xk − x̄k
uk = ūk + δu∗k
= ūk + Kk δxk + αdk
xk+1 = f (xk , uk )
where α is the step size, typically used to perform a simple line search (see Section ??).
4
2.6 Square-Root Backward Pass (V3)
√ √ √
2.6.1 A+ B→ A+B
√
A
Q, R = QR( √ )
B
√
R= A+B
2.6.2 Method
We approximate the state-action cost-to-go Q(x, u) using a second-order Taylor series expansion:
T T
1 δx Qxx Qxu δx Qx δx
δQ(x, u) = +
2 δu Q ux Qxx δu Qu δu
√
p Tp T 0T 0
√ 0
T Lxx
Qxx = Lxx Lxx + A S S A = Lxx SA
S0A
√
p Tp T Luu
Luu + B T S 0T S 0 B = 0
√
Quu = Luu Luu SB
S0B
√ T√
We can factor Qxx → Qxx Qxx using the above technique:
√
p Lxx
−, Qxx = QR( )
S0A
The square root of the Hessian of the cost-to-go S = Qxx + K T Quu K + K T Qux + Qu xT K is derived:
T
I Qxx Qxu I
S=
K Qux Quu K
5
T T
αT β
Qxx Qxu α 0nxm α β α α
= T = T
Qux Quu β γT 0mxn γ β α βT β − γT γ
p
α= Qxx
p −T
β = Qxx Qux
q
p Tp
γ= Quu Quu − β T β
√
β I α
S=
0mxn γ K
α + βK
=
γK
√ √
Note: that S ∈ Rnxn , S ∈ R(n+m)xn and SN [1:n,1:n] = chol(SN )
2.7 Regularization
Due to limited numerical precision, it is common for Quu to become not positive definite. To address this problem,
regularization is added in a way that is equivalent to using trust region methods. Additionally, there are two options
for regularization. The first penalizes deviations from a control trajectory and the second penalizes deviations for
the state trajectory.
Option 1:
Q̃uu = `uu + B T S 0 B + ρI
d = −Q̃−1
uu Qu
K = −Q̃−1
uu Qux
1 T
∆V = d Quu d + dT Qu
2
s = Qx + K T Quu d + K T Qu + QTux d
S = Qxx + K T Quu K + K T Qux + QTux K
Option 2:
Q̃uu = `uu + B T (S 0 + ρI)B
Q̃ux = `ux + B T (S 0 + ρI)A
d = −Q̃−1
uu Qu
K = −Q̃−1
uu Q̃ux
1 T
∆V = d Quu d + dT Qu
2
s = Qx + K T Quu d + K T Qu + QTux d
S = Qxx + K T Quu K + K T Qux + QTux K
Note the subtle but very important distinctive use of Quu and Q̃uu (and Q̃ux ). The former is used to estimate
the cost-to-go and is propagated backward, while the regularized versions are used to compute the optimal gains.
Generally, the second option is more robust and is preferred.
6
3 Constraints
3.1 Augmented Lagrange Method
In order to solve systems with equality and inequality constraints we define a new cost function:
N
X −1
LA (x0 , U ; µ, λ) = `f (xN ) + {`(xk , uk )}
k=1
N −1
1 X 1
+ cN (xN )T IµN cN (xN ) + λTN cN (xN ) + { ck (xk , uk )T Iµk ck (xk , uk ) + λTk ck (xk , uk )}
2 2
k=1
cik (x, u) = 0, i ∈ E
cik ∈ C 1 , ∈ IR
cik (x, u) ≤ 0, i ∈ I
cik ∈ C 1 , ∈ IR
using subscripts to denote time index and superscripts to denote a particular constraint. The vector ck ∈ IRp is the
ordered (equality, then inequality), vertical concatenation of all p constraints at that time step.
The matrix Iµk ∈ IRpxp is used to turn on and off feasible inequality constraints and is defined as follows:
(
µik if any: i ∈ E, cik ∈ I > 0, λik > 0
Iµk [i, i] =
0 otherwise
∂c ∂c
where cx = ∂x |x,u , cu = ∂u |x,u Additionally the boundary conditions SN , sN are augmented:
The backward pass can be performed as before using these augmented versions.
7
4 Infeasible Initial Trajectory
Given a desired state trajectory Xd : {xd1 , ...xdn } we must find a set of artificial/slack controls Ui : {ui1 , ...uin−1 } to
achieve this state trajectory despite the system dynamics. At each time step we solve for uik :
Before simulating the dynamics at the next step remember to apply the artificial control we just calculated: xk+1 + =
uik
5 Minimum Time
6 Taylor Series Approximation
Throughout the following derivations we use Taylor polynomials to approximate nonlinear functions. We are typi-
cally interested in first or second order approximations of nonlinear functions of two variables, the state and control.
The following derivations may prove helpful.
A second order Taylor Series approximation of f (x), a nonlinear scalar valued function that is dependent one
variable (x ∈ R) and linearized about x̄ (which is not necessarily zero):
f (x) → (13)
2
∂f 1∂ f
f (x̄ + δx) ≈ f (x̄) + (x − x̄) + (x − x̄)2 (14)
∂x x̄ 2 ∂x2 x̄
∂f 1 ∂2f
≈ f (x̄) + δx + δx2 (15)
∂x x̄ 2 ∂x2 x̄
A second order Taylor Series approximation of f (x), a nonlinear vector valued function that is dependent one variable
(x ∈ Rn ) and linearized about x̄ (which is not necessarily zero):
f (x) → (16)
2
∂f 1 ∂ f
f (x̄ + δx) ≈ f (x̄) + (x − x̄) + (x − x̄)T 2 (x − x̄) (17)
∂x x̄ 2 ∂x x̄
∂f 1 T ∂2f
≈ f (x̄) + δx + δx δx (18)
∂x x̄ 2 ∂x2 x̄
The most complicated approximation we perform is a second order Taylor Series approximation of a nonlinear
function f that is dependent on three variables. The procedure is the same as before:
f (x, y, z) →
f (x̄ + δx, ȳ + δy, z̄ + δz)
∂f ∂f ∂f
≈ f (x̄, ȳ, z̄) + (x − x̄) + (y − ȳ) + (z − z̄)
∂x x̄,ȳ,z̄ ∂y x̄,ȳ,z̄ ∂z x̄,ȳ,z̄
1 ∂2f 1 ∂2f 1 ∂2f
(x − x̄)T 2 (x − x̄) + (y − ȳ)T 2 (y − ȳ) + (z − z̄)T 2 (z − z̄)
2 ∂x x̄,ȳ,z̄ 2 ∂y x̄,ȳ,z̄ 2 ∂z x̄,ȳ,z̄
1 ∂2f 1 ∂2f
(x − x̄)T (y − ȳ) + (x − x̄)T (z − z̄)
2 ∂x∂y x̄,ȳ,z̄ 2 ∂x∂z x̄,ȳ,z̄
1 ∂2f 1 ∂2f
+ (y − ȳ)T (x − x̄) + (y − ȳ)T (z − z̄)
2 ∂y∂x x̄,ȳ,z̄ 2 ∂y∂z x̄,ȳ,z̄
1 ∂2f 1 ∂2f
+ (z − z̄)T (x − x̄) + (z − z̄)T (y − ȳ)
2 ∂z∂x x̄,ȳ,z̄ 2 ∂z∂y x̄,ȳ,z̄
8
7 Appendix
7.1 Square-Root Backward Pass(DONT USE)
It is common for S to become ill-conditioned, which causes numerical instability when performing the updates in (19).
This can be quantified using a conditioning number, which is a ratio between the largest and smallest eigenvalues of
a square matrix [Kaminkski’71] To alleviate numerical issues, we can derive a backward pass using only the square
root of S, defined as S = LLT , where L is the is value to be calculated and propagated backward in time. This is
done by using the a factor of S when calculating K, d, s, S (and Quu ) during the backward pass. To reduce visual
noise, we drop subscripts and define Sk ≡ S̄ and Sk+1 ≡ S. We also define A−T ≡ (A−1 )T .
K = Q−1
uu Qux
−1
= `uu + B T SB B T SA
−1
= `−1
uu B
T
S −1 + B`−1
uu B
T
A (Matrix Inversion Lemma2 )
−1
= `−1
uu B
T
L−T L−1 + B`−1 uu B
T
A ((A−1 )T = (AT )−1 , S = LLT )
−1
= `−1
uu B
T
L−T L−1 + L−T LT B`−1 T
uu B LL
−1
A (AA−1 = I)
h i−1
= `−1
uu B
T
L−T (I + LT B`−1 T
uu B L)L
−1
A (Factor out L−T (left), L−1 (right))
−1
K = `−1 T T −1 T
uu B L I + L B`uu B L LT A ((ABC)−1 = C −1 B −1 A−1 )
Quu = B T SB + `uu
= B T LLT B + LR LTR (S = LLT , LR = chol(R))
= MMT
where M ≡ B T L
LR
= QRRT QT (Q, R = QR(M ))
LQuu LTQuu = QDQ T
(D is a diagonal matrix)
↓
LQuu = QD1/2
d = Q−1 T
uu Qu
−1
= LQuu LTQuu Qu
= L−T (I + GG )L T −1
where G ≡ LT BL−T
R ,G ∈ R
nxm
9
= AT L(I + W ΛW T )−1 LT A + `xx (W ΛW T = LDL(GGT ))
= AT L(W W T + W ΛW T )−1 LT A + `xx (W W T = I, W is orthogonal)
= AT L(W (I + Λ)W T )−1 LT A + `xx (Factor out W, W T )
= AT LW −T (I + Λ)−1 W −1 LT A + `xx
= AT LW (I + Λ)−1 W T LT A + `xx (W T = W −1 , W is orthogonal)
= AT LW (I + Λ)−1/2 (I + Λ)−1/2 W T LT A + LQ LTQ (LQ = chol(`xx ))
T
= MM
where M ≡ AT LW (I + Λ)−1/2
LQ
= QRRT QT (Q, R = QR(M ))
T T T
L̄L̄ = QV DV Q (V, D = LDL(RRT ))
↓
L̄ = QV D1/2
Finally, we can calculate s̄:
s̄ = Qx − K T Qu + K T QTuu d − QTux d
= Qx − (B T SA)T (`uu + B T SB)−T Qu + (B T SA)T (`uu + B T SB)−1 Qu − (B T SA)T (`uu + B T SB)−1 Qu
= Qx − (B T SA)T (`uu + B T SB)−T Qu ((ABC)T = C T B T AT )
= Qx − AT S T B(`uu + B T SB)−T Qu
−1
= Qx − AT S −T + B`−Tuu B
T
B`−T
uu Qu (Matrix Inversion Lemma2 )
−1
= Qx − AT L−T L−1 + B`−T uu B
T
B`−T
uu Qu ((A−1 )T = (AT )−1 , S = LLT )
−1
= Qx − AT L−T L−1 + L−T LT B`−T T
uu B LL
−1
B`−T
uu Qu (AA−1 = I)
h i−1
= Qx − AT L−T (I + LT B`−T T
uu B L)L
−1
B`−T
uu Qu (Factor out L−T (left), L−1 (right))
s̄ = Qx − AT L(I + LT B`−T T
uu B L)
−1 T
L B`−T
uu Qu ((ABC)−1 = C −1 B −1 A−1 )
10
−
Lxu = 2M1T Lm m
xu + 4M1 Lxx M2 + Lxu
Lxy = M1T Lm
xx
Lxv = 2M1 Lm
xu
−
Luu = Lm T m m m
uu + 2(M2 Lxu + Lux M2 ) + 4M2 Lxx M2 + Luu
1
Luy = Lm + M2T Lm
2 ux xx
Luv = Lm T m
uu + 2M2 Lxu
1
Lyy = Lm + L+
4 xx xx
1
Lyv = Lm + L+
2 xy xu
Lvv = Lm +
uu + Luu
Lx = Lmx M1 + Lx
+
1 −
Lu = Lm + Lmx M2 + Lu
2 u
1
Ly = Lm + L+
4 x x
1
Lv = Lm + L+
2 u u
11
= min `x + sk+1 A δxk + `u + sk+1 B δuk (Combine Terms)
δuk
1 1
+ δxTk `xx + AT Sk+1 A δxk + δuTk `uu + B T Sk+1 B δuk
2 2
1 T 1
+ δuk `ux + B Sk+1 A δxk + δxTk `xu + AT Sk+1 B δuk
T
2 2
7.4 (
unnecssary plug in for s,S)
which is easy to verify that all values are either functions of the current state and control (subscripts k), or are
from the next time step. By working backwards, the Sk , sk , and u∗k values can be calculated for each time step.
subsectionincorrect foh derivation
Without loss of generality, we assume knowledge of the points (xk , uk , xk+1 , uk+1 ) and assume tk = 0, tk+1 = dt. By
specifying 3 known points we can solve for the coefficients (a, b, c). We pick the points xk , xk+1 , ẋk = f (xk , uk ):
xk 0 0 1 a
ẋk = 0 1 0 b
xk+1 dt2 dt 1 c
(23)
a
= T b
c
Solving this linear equation gives
1
a= (−xk − ẋk dt + xk+1 )
dt2
b = ẋk (24)
c = xk
We can now calculate xm by evaluating the spline (Eq. 22) at dt/2:
1 2 1 a
xm = 4 dt b
2 dt 1
c
1 2 1 −1 xk
= 4 dt ẋk
2 dt 1 T (25)
xk+1
1 xk
= 3 dt 1 ẋk
4
xk+1
12
which can be verified by either plugging in the expressions for a, b, c in Eq 24 or using a symbolic solver (e.g. SymPy).
In order to express [xk ẋk xk+1 ]T as a linear expression in the desired variables, we need to perform a 1st Order
Taylor-Series expansion of the dynamics:
∂f ∂f
ẋ + δ ẋ ≈ f (x, u) + δx + δu
∂x ∂u
= f (x, u) + A(x, u)δx + B(x, u)δu (26)
It is important that these Jacobian matrices are distinct from the ones for linearized discrete dynamics in (43). These
Jacobians are calculated on the continuous dynamics equation.
Using this result we can now express the following:
δxk
δxk In 0 0 0
δ ẋk = A B 0 0 δuk
δxk+1 (27)
δxk+1 0 0 In 0
δuk+1
δuk+1
With an expression for xm , all we need is an expression for um . This expression is obtain using a simple interpolation:
um = 21 (uk + uk+1 ). Using both of these relationships we can can convert between point sets:
δxk In 0 0 0
δuk 0 Im 0 0
δxk
δxm [M ] δuk
δum = 0
1
1
0 2 δxk+1
2
δxk+1 0 0 In 0 δuk+1
δuk+1 0 0 0 Im (29)
δxk
δuk
=E δxk+1
δuk+1
13
7.4.2 Approximating Stage Cost
We can find a quadratic expression for L(xk , uk , xk+1 , uk+1 ) by taking a 2nd Order Taylor Series Expansion of the
integral term in (41):
T T
L− L−
δxk xx xu δxk
δuk L− L− δuk
ux uu
dt δxm 4Lm
xx 4Lm
xu
δxm
δLk ≈ (30)
6 δum
4Lm
ux 4Lm
uu
δum
δxk+1 L+
xx L+
xu
δxk+1
δuk+1 L+
ux L+
uu δuk+1
T
δxk
δuk
dt − + δxm
L−
+ Lx u 4Lm
x 4Lm
u L+
x Lu (31)
6 δum
δxk+1
δuk+1
L− L−
T xx xu
−
L−
δxk Lux
uu
δxk
dt
δuk E T
4Lm
xx 4Lm
xu
δuk
= E (32)
6 δxk+1
4Lm
ux 4Lm
uu
δxk+1
δuk+1 L+xx L+
xu
δuk+1
L+ux L+
uu
δxk
dt − δu k
L−
4Lm 4Lm L+ L+
+ Lx u x u x u E
(33)
6 δxk+1
δuk+1
∂2L ∂2L
where Lx := ∂L
∂x , Lxx := ∂x2 , Lxu := ∂xu , etc. and L− , Lm , L+ are the partials evaluated at (xk , uk ), (xm , um ), (xk+1 , uk+1 ),
respectively.
Using a symbolic solver or chugging through the matrix multiplication by hand we arrive at the final expression for
L(xk , uk , xk+1 , uk+1 ):
7.5 Calculating P̄
Once we have δ L̄, we also need δP¯ from Equation ?? in order to calculate the elements of Q in Equation 51. We
simply plug in the linearized discrete dynamics (Eq. 43) into our cost-go-to for the next time step:
T
1 δy Syy Syv δy δy
δP (δy, δv) = + Sy Sv (34)
2 δv Svy Svv δv δv
T
1 Aδx + Bδu + Cδv Syy Syv Aδx + Bδu + Cδv
δ P̄ (δx, δu, δv) = (35)
2 δv Svy Svv δv
Aδx + Bδu + Cδv
+ Sy Sv
δv
T
δx Gxx Gxu Gxv δx δx
1
= δu Gux Guu Guv δu G + Gx Gy Gv δu (36)
2
δv Gvx Gvu Gvv δv δv
Gxx = AT Syy A
Guu = B T Syy B
Gvv = C T Syy C + C T Syv + Svy C + Svv (37)
T
Gxu = A Syy B
14
Gxv = AT Syy C + AT Syv
Guv = B T Syy C + B T Syv
Gx = Sy A
Gy = Sy B (38)
Gv = Sy C + Sv
However, we need S in its square root form U . To accomplish this, we perform recursive rank-1 downdates on
−1
Wxx using the rows of Wuu Qux . An example of this process in Julia:
U = LinAlg . Cholesky (Wxx, ’ U’ )
tmp = Wuu’ \ Qux
f o r i = 1 : s i z e ( luu , 1 )
U = LinAlg . lowrankdowndate (U, tmp [ i , : ] )
end
U = U [ : U]
1 1
δV (xk ) = Qx δxk + Qu δxu + δxTk Qxx δxk + δuTk Quu δuk
2 2
1 T 1 T T
+ δuk Qux δxk + δxk Qux δuk
2 2
1 1
δVk = Qx δxk + Qu (−Quu (QTu + Qux δxk )) + δxTk Qxx δxk + (−Q−1
−1 T T −1 T
uu (Qu + Qux δxk )) Quu (−Quu (Qu + Qux δxk ))
2 2
1 1 T T
+ (−Q−1 T T −1 T
uu (Qu + Qux δxk )) Qux δxk + δxk Qux (−Quu (Qu + Qux δxk ))
2 2
= Qx δxk − Qu Q−1 T −1
uu Qu − Qu Quu Qux δxk
1 1
+ δxTk Qxx δxk + (δxTk QTux + Qu )Q−T T
uu (Qu + Qux δxk )
2 2
1 1
+ (−Qu Q−T T T −T T T −1 T T T −1
uu Qux δxk − δxk Qux Quu Qux δxk ) + (−δxk Qux Quu Qu − δxk Qux Quu Qux δxk )
2 2
= Qx δxk − Qu Q−1 T −1
uu Qu − Qu Quu Qux δxk
1 1
+ δxTk Qxx δxk + (δxTk QTux Q−T T −T T T T −T −T
uu Qu + Qu Quu Qu + δxk Qux Quu Qux δxk + Qu Quu Qux δxk )
2 2
15
1 1
+ (−Qu Q−T T T −T T T −1 T T T −1
uu Qux δxk − δxk Qux Quu Qux δxk ) + (−δxk Qux Quu Qu − δxk Qux Quu Qux δxk )
2 2
−1 T 1
= −Qu Quu Qu + (Qu Q−T T −1 −1 −1
uu Qu ) + (Qx − Qu Quu Qux + Qu Quu Qux − 1Qu Quu Qux )δxk
2
1
+ δxTk (Qxx + QTux Q−T T −T
uu Qux − 2Qux Quu Qux )δxk
2
1 1 T
= − (Qu Q−T T −1 T −T
uu Qu ) + (Qx − Qu Quu Qux )δxk + δxk (Qxx − Qux Quu Qux )δxk
2 2
1
min LA (xk , uk , λk ) = L(xk , uk ) + Vk+1 (xk+1 ) + ck (xk , uk )T Iµk ck (xk , uk ) + λTk ck (xk , uk )
xk ,uk 2
Where L is the stage cost and may incorporate infeasible or minimum time costs.
For notational convenience we define zk = [xk , uk ]T and Q(zk ) = L(zk ) + Vk+1 (zk+1 ). Active constraints are
denoted with a bar, for example: c̄. All equality and any violating inequality constraints are considered active.
16
∂L2A ∂c̄ T ∂LA
2
δz + δλ = −
∂z ∂z ∂z
∂c̄ T
δz = −c̄
∂z
−1
∂L2A ∂c̄
2
∂c̄ ∂LA
If ∂z 2 is invertible and ∂z is full rank then the system can be solved. Premultiply the first equation by ∂z ∂z 2 :
−1 −1 −1
∂c̄ ∂L2A ∂L2A ∂c̄ ∂L2A ∂c̄ T ∂c̄ ∂L2A ∂LA
δz + δλ = −
∂z ∂z 2 ∂z 2 ∂z ∂z 2 ∂z ∂z ∂z 2 ∂z
−1 T −1
∂c̄ ∂L2A ∂c̄ ∂c̄ ∂L2A ∂LA
−c̄ + δλ = −
∂z ∂z 2 ∂z ∂z ∂z 2 ∂z
−1 −1
∂c̄ ∂L2A ∂c̄ T −1 ∂c̄ ∂L2A ∂LA
δλ = ( ) (c̄ − )
∂z ∂z 2 ∂z ∂z ∂z 2 ∂z
Z tf
min `f (x(tf )) + `(x, u)dt
u,tf 0
s.t. ẋ(t) = f (x(t), u(t)) + ui (t)
xmin ≤ x(t) ≤ xmax , 0 ≤ t ≤ tf
umin ≤ u(t) ≤ umax
h(x(t), u(t)) = 0
g(x(t), u(t)) ≤ 0
ui (t) = 0
tfmin ≤ tf ≤ tfmax
x(tf ) = xf
x(0) = x0
17
hk (xk , uk ) = 0
gk (xk , uk ) ≤ 0
uik = 0, ∀k = 1, ..., N − 1
p p
dtmin ≤ hk ≤ dtmax
hk = hk+1 , ∀k = 1, ..., N − 2
xN = xf
x1 = x0
N −1
1 X
L(x1:N , ū1:N , λ) = (xN − xf )T Qf (xN − xf ) + Lk (xk , uk , xk+1 , uk+1 )
2
k=1
N
X −1
+ Rm h2
k=1
N −1
X 1 T
+ u Ri uik
2 ik
k=1
N
1 X 1
+ c(xN , uN )T IµN c(xN , uN ) + λTN c(xN , uN ) + c(xk , uk , xk+1 , uk+1 )T Iµk c(xk , uk , xk+1 , uk+1 ) + λTk c(xk , uk , xk+1 , uk+1 )
2 2
k=1
We define:
h2
Lk (xk , uk , xk+1 , uk+1 ) = (`(xk , uk ) + 4`(xm , um ) + `(xk+1 , uk+1 ))
6
1 h2 h2
xm = (xk + xk+1 ) + ẋk − ẋk+1
2 8 8
uk + uk+1
um =
p 2
hk = dtk
uk
ūk = hk
uik
u
ûk = k
hk
18
where the horizontal line indicates the separation between inequality (above) and equality (below) constraints.
Gradients
0m̄×n
0m̄×n
In
∇xk c(xk , ūk , xk+1 , ūk+1 ) = −In
∇x cI (xk , uk )
∇x cE (xk , uk )
01×n
Im(m̄,m̄)[k6=N ] 0m̄×n
−Im 0m̄×n
(m̄,m̄)[k6=N ]
0n×mm
∇ūk c(xk , ūk , xk+1 , ūk+1 ) = 0n×mm
[∇ū cI (xk , uk ) 0]
[∇ū cE (xk , uk ) 0]
01×m 1[k < N − 1] 01×n
∇xk+1 c(xk , ūk , xk+1 , ūk+1 ) = 0p×n
0p−1×mm
∇ūk+1 c(xk , ūk , xk+1 , ūk+1 ) =
01×m −1[k < N − 1] 01×n
8.1 Notation
For convenience we define the following:
x = xk
u = uk
y = xk+1
v = uk+1
19
4h2
Lxv = `2xv
6
4h2
Luy = `2uy
6
4h2
Luv = `2uv
6
2
4h
Lyv = `2yv
6
Minimum time
Lx = Lx
Lu
Lû = 2h
6 `1 + L2h + 2h
6 `3 + 2Rm h
Ly = Ly
L
Lv̂ = v
0
Lxx = Lxx
( 2h
Luu 6 `1u + L2uh )
Lûû = 2h
( 6 `1u + L2hu )T ( 6 `1 + L2hh + 62 `3 + 2Rm )
2
Lyy = Lyy
L 0
Lv̂v̂ = vv
0 0
( 2h
Lxû = Lxu 6 `1x + L2xh )
Lxy = Lxy
Lxv̂ = Lxv 0
T
Lûy = Lyu ( 2h
6 `3y + L2yh )
T
( 2h
L 6 `3v + L2vh )
Lûv̂ = vu
0 0
T
Lyv̂ = Lyv 0
2
xmh 7 = h(fc (x, u) − fc (y, v))
8
h2
xmu = Bu
8
h2
xmy = 0.5I − Ay
8
h2
xm v = Bb
8
`2h = xTmh Q(xm − xf )
2
`2hh = ((fc (x, u) − fc (y, v))T Q(xm − xf ) + h(fc (x, u) − fc (y, v))T Qxmh
8
4
L2h = (h2 `2h + 2h`2 )
6
4
L2hh = (2h`2h + 2`2 + h2 `2hh + 2h`2h )
6
4 2
L2hu = (2h`2u + h3 (BuT Q(xm − xf ) + xTmu Q(fc (x, u) − fc (y, v))))
6 8
4 h2 2
L2xh = (2h`2x + h2 (0.5I + ∗ (A)Tx Qxmh + hATx Q(xm − xf ))
6 8 8
2
4 h 2
L2uh = (2h`2u + h2 ( BuT Qxmh + hBu Q(xm − xf ))
6 8 8
20
4 h2 2
L2yh = (2h`2y + h2 (− ATy Qxmh + hAy Q(xm − xf ))
6 8 8
4 h2 2
L2vh = (2h`2v − h2 ( BvT Qxmh + hBv Q(xm − xf ))
6 8 8
Infeasible
-Note: the bold variable is used to indicate that either u or û can be used if the problem is infeasible or minimum
time and infeasible, respectively
Lx = Lx
Lu
Lũ =
Ri ui
Ly = Ly
L
Lṽ = v
0
Lxx = Lxx
L 0
Lũũ = uu
0 Ri
Lyy = Lyy
L 0
Lṽṽ = vv
0 0
Lxũ = Lxu 0
Lxy = Lxy
Lxv = Lxv 0
T
L y
Lũy = u
0
T
Lvu 0
Lũṽ =
0 0
T
Lyṽ = Lyv 0
8.3 Preliminaries
Similar to the setup for the regular iLQR problem (Section ??), we define a generic nonlinear cost function
Z tf
J = `N (xN ) + `(x, u)dt (40)
0
which we can approximate over N discrete time steps using Simpson integration:
N −1
X dt
J ≈ `N (xN ) + (`(xk , uk ) + 4`(xm , um ) + `(xk+1 , uk+1 ))
6
k=1
(41)
N
X −1
= `N (xN ) + L(xk , uk , xk+1 , uk+1 )
k=1
where xm , um are the controls at the midpoint of the interval [k, k + 1].
We choose to linearly interpolate the controls such that
uk + uk+1
um = (42)
2
and define a function g that such xm = g(xk , uk , xk+1 , uk+1 ), which will be derived later.
21
We discretize the dynamics as before, but now include a dependence on the control at k + 1 to implement a first
order hold on the controls so that our dynamics are now xk+1 = fd (xk , uk , uk+1 ), with a first-order Taylor-series
approximation:
δxk+1 = A(xk , uk , uk+1 )δxk + B(xk , uk , uk+1 )δuk + C(xk , uk , uk+1 )δuk+1 (43)
8.4 Cost-To-Go
With a given cost function, we can apply Bellman’s Principle of Optimality to define the optimal cost-to-go Vk (x)
by the recurrence relation:
VN = `f (xN )
Vk = min {L(xk , uk , xk+1 , uk+1 ) + Vk+1 (fd (xk , uk , uk+1 ))} (44)
uk ,uk+1
However, the minimization is now over controls at time steps k and k + 1. Since the cost at the previous time step
k − 1 is dependent on the control uk , we cannot optimize over uk without taking into account the effect at k − 1. To
avoid this, we define a new control-dependent cost-to-go function:
P (xk , uk ) ≡ min L(xk , uk , xk+1 , uk+1 ) + Pk+1 (xk+1 , uk+1 )
uk+1
(45)
= min Q(xk , uk , xk+1 , uk+1 )
uk+1
such that
Vk = min P (xk , uk ) (46)
uk
where s ∈ Rn+m and S ∈ R(n+m)×(n+m) are the gradient and Hessian of δP , similar to their definitions for the
normal iLQR case, except that now they are functions of both the state and control and the current time step.
22
The terms of the Q are composed of the elements of L(x, u, y, v) and P (y, v). These calculations and the substitution
of the dynamics are detailed in Sections to avoid clutter when deriving the dynamic programming step.
To calculate the optimal modification to the nominal control at the next time step δv ∗ , we take the derivative of δQ
with respect to δv and solve for the minimizing δv ∗ :
∂δQ
= Qv + Qvv δv + Qvx δx + Qvu δu
∂v
δv ∗ = −Q−1 (52)
vv (Qvx δx + Qvu δu + Qv )
≡ Kδx + bδu + d
It is important to note that the subscripts on the gains match the time index of the control deviation being calculated,
not the deviations by which they are multiplied (for more detail see Section 7.6)
By plugging in δv ∗ into Q we find our approximated cost-to-go which we can propagate backward one time step.
T
Q∗xx Q∗xu δx
1 δx δx
δP = δQ∗ = + Q∗x Q∗u
∗ ∗
2 δu Qux Quu δu δu
T (53)
∗ 1 δx δx δx
= δQ = S +s
2 δu δu δu
This completes the dynamic programming step. The equations to calculate S and s at the current time step are
derived in a following section.
from Equation 46. This minimization can now be carried out since u1 does not affect any previous time steps. This
problem is identical to that of iLQR:
δu∗1 = −Q−1
uu (Qux δx1 + Qx )
≡ K1 δx1 + d1
8.7 Calculating L
We now find a closed-form expression for δL(δx, δu, δy, δv) in Equation ??, which is the 2nd order approximation of
L(x, u, y, u)
The state x(t) over each interval tk < t < tk+1 can be approximated using a cubic polynomial:
x(0) = xk
23
ẋ(0) = f (xk , uk )
x(dt) = xk+1
ẋ(dt) = f (xk+1 , uk+1 )
The coefficients enter into the system linearly and can be solved for as follows:
xk 0 0 0 1 a
ẋk 0 0 1 0 b
xk+1 = dt3
dt2 dt 1 c
ẋk+1 3dt2 2dt 1 0 d
−2
2 1 1
a dt3 dt2 dt3 dt2 xk
b −32 −2 3 −1
ẋk
= dt dt dt2 dt
c 0 1 0 0 xk+1
d 1 0 0 0 ẋk+1
To evaluate the midpoint xm :
1 dt dt
xm = (xk + xk+1 ) + ẋk − ẋk+1
2 8 8
1 dt dt
= (xk + xk+1 ) + f (xk , uk ) − f (xk+1 , uk+1 )
2 8 8
= g(xk , uk , xk+1 , uk+1 )
We can consider the pieces that sum to form L(x, u, y, v) separately (i.e., `(x, u), `(xm , um ), `(y, v)). First, we
consider the second order expansion of `(x, u):
24
∂` ∂`
+ |x,u δx + |x,u δu
∂x ∂u
1 ∂2` 1 ∂2`
+ δx 2 |x,u δx + δu 2 |x,u δu
2 ∂x 2 ∂u
∂`2 ∂`2
Note that for our quadratic stage cost there are no cross terms so ∂x∂u and ∂u∂x are both zero.
The terms of interest for our quadratic stage cost are:
∂`
|x,u = Q(x − xf )
∂x
∂`
|x,u = Ru
∂u
∂2`
|x,u =Q
∂x2
∂2`
|x,u =R
∂u2
The expansion for `(y, v) is defined identically, using y and v in the appropriate places.
`1x = Q(x − xf )
`1u = Ru
`1xx = Q
`1uu = R
`3y = Q(y − xf )
`3v = Rv
`3yy = Q
`3vv = R
The expansion of `(xm , um ) requires application of the matrix chain rule, our cubic interpolation for xm , linear
interpolation for um , and linear approximation of the continuous dynamics:
∂xm T ∂`
`2x =
∂x ∂xm
1 dt
= ( I + Ax )T Q(xm − xf )
2 8
T
∂xm ∂` ∂um T ∂`
`2u = +
∂u ∂xm ∂u ∂um
dt 1
= ( Bu )T Q(xm − xf ) + Rum
8 2
∂xm T ∂`
`2y =
∂y ∂xm
1 dt
= ( I − Ay )T Q(xm − xf )
2 8
∂xm T ∂` ∂um T ∂`
`2v = +
∂v ∂xm ∂v ∂um
dt 1
= (− Bv )T Q(xm − xf ) + Rum
8 2
∂xm T ∂ 2 ` ∂xm
`2xx =
∂x ∂x2m ∂x
25
1 dt 1 dt
= ( I + Ax )T Q( I + Ax )
2 8 2 8
∂xm T ∂ 2 ` ∂xm ∂um T ∂ 2 ` ∂um
`2uu = +
∂u ∂x2m ∂u ∂u ∂u2m ∂u
dt dt 1 1
= ( Bu )T Q( Bu ) + R
8 8 2 2
∂xm T ∂ 2 ` ∂xm
`2yy =
∂y ∂x2m ∂y
1 dt 1 dt
= ( I − Ay )T Q( I − Ay )
2 8 2 8
∂xm T ∂ 2 ` ∂xm ∂um T ∂ 2 ` ∂um
`2vv = +
∂v ∂x2m ∂v ∂v ∂u2m ∂v
dt dt 1 1
= (− Bv )T Q(− Bv ) + R
8 8 2 2
∂xm T ∂ 2 ` ∂xm
`2xu =
∂x ∂x2m ∂u
1 dt dt
= ( I + Ax )T Q( Bu )
2 8 8
∂xm T ∂ 2 ` ∂xm
`2xy =
∂x ∂x2m ∂y
1 dt 1 dt
= ( I + Ax )T Q( I − Ay )
2 8 2 8
T 2
∂xm ∂ ` ∂xm
`2xv =
∂x ∂x2m ∂v
1 dt dt
= ( I + Ax )T Q(− Bv )
2 8 8
∂xm T ∂ 2 ` ∂xm
`2uy =
∂u ∂x2m ∂y
dt 1 dt
= ( Bu )T Q( I − Ay )
8 2 8
∂xm T ∂ 2 ` ∂xm ∂um T ∂ 2 ` ∂um
`2uv = +
∂u ∂x2m ∂v ∂u ∂u2m ∂v
dt dt 1 1
= ( Bu )T Q(− Bv ) + R
8 8 2 2
∂xm T ∂ 2 ` ∂xm
`2yv =
∂y ∂x2m ∂v
1 dt dt
= ( I − Ay )T Q(− Bv )
2 8 8
dt
Collect the expanded terms from `(x, u), `(xm , um ), `(y, v). Importantly, multiply by the correct scaling factor 6
4dt
or 6 :
dt 4dt 1 dt
Lx = Q(x − xf ) + ( I + Ax )T Q(xm − xf )
6 6 2 8
dt 4dt dt T 1
Lu = Ru + ( Bu ) Q(xm − xf ) + Rum
6 6 8 2
dt 4dt 1 dt
Ly = Q(y − xf ) + ( I − Ay )T Q(xm − xf )
6 6 2 8
dt 4dt dt 1
Lv = Rv + (− Bv )T Q(xm − xf ) + Rum
6 6 8 2
26
dt 4dt 1 dt 1 dt
Lxx = Q+ ( I + Ax )T Q( I + Ax )
6 6 2 8 2 8
dt 4dt dt T dt 1 1
Luu = R+ ( Bu ) Q( Bu ) + R
6 6 8 8 2 2
dt 4dt 1 dt T 1 dt
Lyy = Q+ ( I − Ay ) Q( I − Ay )
6 6 2 8 2 8
dt 4dt dt T dt 1 1
Lvv = R+ (− Bv ) Q(− Bv ) + R
6 6 8 8 2 2
4dt 1 dt dt
Lxu = ( I + Ax )T Q( Bu )
6 2 8 8
4dt 1 dt T 1 dt
Lxy = ( I + Ax ) Q( I − Ay )
6 2 8 2 8
4dt 1 dt T dt
Lxv = ( I + Ax ) Q(− Bv )
6 2 8 8
4dt dt 1 dt
Luy = ( Bu )T Q( I − Ay )
6 8 2 8
4dt dt dt 1 1
Luv = Bu )T Q(− Bv ) + R
6 8 8 2 2
4dt 1 dt dt
Lyv = ( I − Ay )T Q(− Bv )
6 2 8 8
T
1 δy Syy Syv δy δy
δP (δy, δv) = + Sy Sv (56)
2 δv Svy Svv δv δv
T
1 Aδx + Bδu + Cδv Syy Syv Aδx + Bδu + Cδv
δP (δx, δu, δv) = (57)
2 δv Svy Svv δv
Aδx + Bδu + Cδv
+ Sy Sv
δv
T
δx Gxx Gxu Gxv δx δx
1
= δu Gux Guu Guv δu G + Gx Gy Gv δu (58)
2
δv Gvx Gvu Gvv δv δv
Gxx = AT Syy A
Guu = B T Syy B
Gvv = C T Syy C + C T Syv + Svy C + Svv (59)
Gxu = AT Syy B
Gxv = AT Syy C + AT Syv
Guv = B T Syy C + B T Syv
Gx = AT Sy
Gy = B T Sy (60)
T
Gv = C Sy + Sv
27
Similarly, we substitute the linearized discrete dynamics into δL(δx, δu, δy, δv) → δL(δx, δu, δv):
T
δx Lxx Lxu Lxy LLxv δx
1 δu Lux Luu Luy LLuv δu
δLk = (61)
2 Aδx + Bδu + Cδv Lyx Lyu Lyy LLyv Aδx + Bδu + Cδv
δv Lvx Lvu Lvy LLvv δv
δx
δu
+ Lx Lu Ly Lv
Aδx + Bδu + Cδv
δv
This simplifies to: (62)
T
δx H Hxu Hxv δx δx
1 xx
δLk = δu Hux Huu Huv δu + Hx Hy Hv δu
2
δv Hvx Hvu Hvv δv δv
where: (63)
Hx = Lx + AT Ly
Hu = Lu + B T Ly (65)
T
Hv = Lv + C Ly
This yields
T
δx Qxx Qxu Qxv δx δx
1
δQ(δx, δu, δv) = δu Qux Quu Quv δu + Qx Qu Qv δu (66)
2
δv Qvx Qvu Qvv δv δv
where:
Qx = Gx + Hx
Qu = Gu + Hu (68)
Qv = Gv + Hv
28
8.8 Calculating S and s
With the gains obtained by optimizing over the control at the next timestep, we are ready to calculate the cost-to-go
Hessian and gradient at the current time step:
T
δx Qxx Qxu Qxv δx δx
1
δP (x, u) = δu Qux Quu Quv δu + Qx Qu Qv δu
2
Kδx + bδu + d Qvx Qvu Qvv Kδx + bδu + d Kδx + bδu + d
= Qx δx + Qu δu + (Qv Kδx + Qv bδu + Qv d)
1
+ (δxT Qxx δx + δuT Quu δu)
2
1
+ (δxT Qxu δu + δuT Qux δx)
2
1
+ (δxT Qxv Kδx + δxT Qxv bδu + δxT Qxv d)
2
1
+ (δuT Quv Kδx + δuT Quv bδu + δuT Quv d)
2
1
+ (δxT K T Qvx δx + δuT bT Qvx δx + dT Qvx δx)
2
1
+ (δxT K T Qvu δu + δuT bT Qvu δu + dT Qvx δu)
2
1
+ (δxT K T Qvv Kδx + δxT K T Qvv bδu + δxT K T Qvv d)
2
1
+ (δuT bT Qvv Kδx + δuT bT Qvv bδu + δuT bT Qvv d)
2
1
+ (dT Qvv Kδx + dT Qvv bδu + dT Qvv d)
2
1 δx Q∗xx Q∗xu δx
δx
+ Q∗x Q∗u
= ∗ ∗
2 δu Qux Quu δu δu
T
1 δx δx δx
= Sk + sk
2 δu δu δu
1
∆Q = Qv d + dT Qvv d
2
29
8.9.2 Rollout with Gains
We assume we have a control U and a trajectory X from the previous iteration, along with the gains K ∈ Rm×n×N , b ∈
Rm×m×N and d ∈ Rm×N . (Note: α ∈ [0, 1] is the line search paramter)
Prior to iterating over the time steps we calculate the deviation of the first control:
since δx1 = 0.
δxk = x̄k − xk
δuk+1 = Kk+1 δxk + bk+1 δuk + αdk+1
ūk+1 = uk+1 + δuk+1
x̄k+1 = fd (x̄k , ūk , ūk+1 )
8.10 Regularization
As before, there are two types of regularization that can be employed: control and state:
Option 1:
Q̃vv = Qvv + ρI
K = −Q̃−1
vv Qvx
b = −Q̃−1
vv Qvu
d = −Q̃−1
vv Qv
1
∆Q = Qv d + dT Qvv d
2
Option 2:
K = −Q̃−1
vv Q̃vx
b = −Q̃−1
vv Q̃vu
d = −Q̃−1
vv Qv
30
Q∗xx = Qxx + Qxv K + K T Qvx + K T Qvv K
Q∗uu = Quu + Qvu b + bT Qvu + bT Qvv b
Q∗ux = Qux + Quv K + bT Qvx + bT Qvv K
1
∆Q = Qv d + dT Qvv d
2
For both regularization types, when timestep k = 1:
Q̃∗uu = Q∗uu + ρI
1
g(xk , uk ) = ck (xk , uk )T Iµk ck (xk , uk ) + λTk ck (xk , uk )
2
While we are using Simpson integration to approximate the state and control stage cost, here we use trapezoidal
integration (which is not dependent on the midpoint state).
LA (X, U ; µ, λ) = `f (xN )
1
+ cN (xN )T IµN cN (xN ) + λTN cN (xN )
2
N −1
X dt
+ `(xk , uk ) + 4`(xm , um ) + `(xk+1 , uk+1 )
6
k=1
N
X
+ g(xk , uk )
k=1
Importantly, we must modify the backward pass. We defined δ Q̄(x, u, y, v) for the first order holdand will modify
it in a similar manner to the Section 3.2:
ˆ = Q̄ + cT I c + cT λ
Q̄ x x x µ x
ˆ
Q̄u = Q̄u + cu Iµ c + cTu λ
T
ˆ = Q̄ + cT I c
Q̄ xx xx x µ x
ˆ
Q̄uu = Q̄uu + cTu Iµ cu
ˆ = Q̄ + cT I c
Q̄xu xu x µ u
The boundary conditions are augmented as well, similar to Section 3.2, they fill the P Hessian and gradient.
31
ŝu = su + (cTuN IµN cN + cTuN λN )
Ŝxu = (cTx Iµ cu )
Ŝux = (cTu Iµ cx )
9.1 Notation
As will be shown, it is natural to treat the time step dt as an additional control. We then define the following:
1. u ∈ Rm = vector of controls for the original problem
2. û ∈ Rm̂ = controls augmented with time
In general, any value related to the controls with a hat will denote values augmented with the time step.
32
9.3.2 Optimization Problem
Using the previous cost function we now formulate the optimization problem:
N
X −1
min `(xN ) + (`(xk , uk ) + ch2 )h2
uk ,hk ∀k
k=1
subject to xlb ≤ xk ≤ xub , ∀k
ulb ≤ uk ≤ uub , ∀k
xN = xf
p
0 ≤ hk ≤ dtmax , ∀k
hk = hk+1 , ∀k
Note that enforcing equality between hk , hk+1 and dtk , dtk+1 are equivalent, so we avoid unnecessary squares in the
constraints by simply enforcing equality on h.
So when taking the first-order Taylor Series expansion we also take the expansion about hk :
∂f ∂f ∂f
δxk+1 = δxk + δuk + δhk
∂x xk ,uk ,hk ∂u xk ,uk ,uk ∂h xk ,uk ,hk
= A(xk , uk , hk )δxk + B(xk , uk , hk )δuk + H(xk , uk , hk )δhk
= A(xk , ûk )δxk + B̂(xk , ûk )
where B̂(xk , ûk ) = B(xk , uk , hk ) H(xk , uk , hk .
33
9.4.1 Terminal Cost-to-Go
Nothing changes here, since the Lagrangian at the terminal state is not a function of dt. So,
∂`N
sN = + ∇x c(xN )T (Iµ,N )c(xN ) + ∇Tx λN
∂x
∂ 2 `N
SN = + ∇x c(xN )T (Iµ,N )∇x c(xN )
∂x2
where
δQ = Qx δx + Qu δu + Qh δh+
δxT Qxx δx + δuT Quu δu + δhT Qhh δh+
δxT Qxu δu + δxT Qxh δh + δuT Quh δh
and Qxx = Lxx + ∇xx Vk+1 (f (xk , uk , hk )) and so forth for the other terms of the expansion.
We re-state the Lagrangian here for reference, prior to defining the partials:
N −1
X 1 1
LA = `(xN ) + c(xN )T Iµ,N c(xN ) + λTN c(xN ) + (`(xk , uk ) + ch2 )h2 + c(xk , ûk )T Iµ,k c(xk , ûk ) + λTk c(xk , ûk ) +
2 2
k=1
N −2
X 1 t
µ (hk − hk+1 )2 + λtk (hk − hk+1 )
2 k
k=1
Taking the expansion of the Lagrangian and the cost-to-go we get the following terms. To simplify the notation,
any variable without a subscript is assumed to at the current time step k, and terms with a superscript (+) or (-)
are the values at the next (k + 1) or previous (k − 1) time step.
Lx = `x h2 + cTx Iµc + cTx λ
Lu = `u h2 + cTu Iµc + cTu λ
Lh = 2`h + 2ch3 + cTh Iµc + cTh λ + µt (h − h+ ) + λt − µt (h− − h) − λ−
t
34
and
Qx = Lx + s+ A
Qû = Lû + s+ B̂
Qxx = Lxx + AT S + A
Qûû = Lûû + B̂ T S + B̂
Qxû = Lxû + AT s+ B̂
The gains can then be readily calculated used an identical procedure as in the non-minimum time case by using these
augmented partials of Q.
δx = x̄k − xk
ūk = uk + Kk δxk + αdk
h̄k = ūk [m̄]
x̄k+1 = f (x̄k , ūk [1 : m], h̄)
where the square brackets are vector indexing operations (similar to syntax used in Julia or Python). Constraints:
In the previous section we used c(xk , ûk ) ∈ Rp , which is equivalent to c(xk , uk , hk ), which we define as:
u −√umax
h − dtmax
û − ûmax
umin − u
ûmin − û
−h
x − x max
c(x, u, h) =
x − x max
= c(x, û) =
x min − x
x min − x
c I (x, u)
cI (x, u)
c E (x, u)
cE (x, u) (hk − hk+1 )[k < N − 1]
(hk − hk+1 )[k < N − 1]
where the horizontal line indicates the separation between inequality (above) and equality (below) constraints.
We now write down the gradients of this equation, since they will be used when re-deriving the backwards pass later:
0m̂×n
0m̂×n
In
∇x c(x, û) = −In
∇x cI (x, u)
∇x cE (x, u)
01×n
Im
−Im
0n̂×m̂
∇û c(x, û) =
0n̂×m̂
[∇u cI (x, u) 0]
[∇u cE (x, u) 0]
1[k < N − 1]
35
The quadratic approximation of the cost function relies heavily on second-order partial derivatives (such as ℓxx, ℓuu, ℓxu) because they define the curvature of the cost function surface around the operating point. These derivatives are key to capturing the interactions between state and control variables and how these interactions influence the trajectory cost. In particular, the second-order terms allow the approximation to encapsulate both separate and joint convexities caused by the state and control variables, resulting in more accurate local modeling of the cost around the nominal trajectory. This is especially crucial for applying Jacobian or Hessian matrix representations in optimization processes like Newton's method or gradient descent, thus enhancing convergence towards optimal control policies .
Incorporating state and control constraints modifies the optimization algorithm's dynamics by adding additional forces in the form of Lagrange multipliers and penalty terms, which act like potential energy barriers preventing the breach of constraints. These constraints redefine the feasible region in the decision space, requiring the optimization process to respect these boundaries while seeking the minimum cost or maximum reward. The mathematical representation of these constraints through augmented terms in the Lagrangian results in modified gradients used in the iterative optimization process, thus influencing the direction and magnitude of gradient descent or ascent operations. This ensures that the findings remain within legally or physically allowable states and transitions without merely considering unconstrained optimal paths .
In discrete time control systems, the Augmented Lagrangian form allows for the inclusion of both equality and inequality constraints, which are critical for ensuring that solutions stay within feasible regions. This formulation adds penalty terms for constraint violations, which guide the optimization process towards satisfying the constraints by altering the path of the state and control variables. The constraints defined in the Augmented Lagrangian include upper and lower limits for state and control variables (xk, uk), continuity of certain variables (hk), and terminal conditions (xN = xf). These aspects ensure that system behaviors remain realistic and adhere to practical limitations .
In the linearization of discrete dynamics, the Taylor series expansion involves calculating the first-order derivatives with respect to state (x), control (u), and time step (h). These derivatives—∂f/∂x, ∂f/∂u, and ∂f/∂h—quantify how small changes in the state, control inputs, and time steps affect the next state xk+1. The state-space representation of these influences is expressed as A, B, and H matrices. The matrices A(xk, uk, hk) and B(xk, uk, hk) are derived from ∂f/∂x and ∂f/∂u, respectively, capturing how variables at the current step contribute to the state transition. The incorporation of ∂f/∂h ensures that variations in the time step are also accounted for, which is particularly important in control scenarios where the time step can change. By linearizing around these parameters, we obtain a simplified model that maintains accuracy over small perturbations .
The controllability of dynamics is crucial for forming an optimized Augmented Lagrangian because it determines whether the system's state can be driven from any initial condition to a desired final state using available controls. Controllability impacts the definition of constraints and penalty terms in the Lagrangian, affecting how effectively the optimization algorithm can navigate towards optimal solutions. An uncontrollable system may lead to infeasible regions or non-convergence since it might be impossible to realize pathway adjustments required by the Lagrange multipliers to satisfy all constraints. Therefore, ensuring the system's controllability allows the augmented Lagrangian to reflect realistic dynamic adjustments within feasible control limits .
The principle of optimality states that an optimal policy must contain optimal sub-policies going forward from any point. In the context of solving the cost-to-go at the terminal state, this principle allows the simplification of decision-making to focus only on the sequence of decisions that minimize cost from the terminal state back to the initial condition. At the terminal state, the value function is initialized using the final cost, usually related to penalty for deviations from a desired end-state. The subsequent backward pass uses this initialization to propagate optimal actions backwards through previous states, ensuring the entire trajectory aligns with the optimal policy. This recursive solution enables the efficient computation of the control strategy by focusing on minimizing compounded incremental costs iteratively .
The backward pass in dynamic programming ensures optimality at each time step by iteratively solving the Bellman's equation: Vk = min uk{ℓ(xk, uk) + Vk+1(f(xk, uk))}. This process begins at the terminal state and moves backwards in time, calculating the optimal control policy by minimizing future costs associated with the current state and control. The backward pass updates the cost-to-go value at each step by incorporating the expected value of taking specific actions, leading to a policy that optimizes the entire trajectory from start to finish. By sequentially determining the best control actions considering future ramifications, dynamic programming ensures that each stage of the trajectory aligns with the optimal strategy for the entire planning horizon .
Matrix G and matrix H in the optimization framework express how deviations in state, control, and other variables affect the quadratic form δQ(x, u, v). Matrix G accounts for the contributions of the partial derivatives of δP, presumably the dynamic cost, while matrix H accounts for δL, which is the incremental Lagrangian cost. Both matrices encapsulate the compound effects of these deviations on the cost landscape, which when combined, allow us to form the full quadratic approximation: δQ(x, u, v) = δL + δP. This combined representation captures how deviations influence the cost-to-go, filtering back into adjustments needed in control variables to minimize costs efficiently .
The forward pass differs from the backward pass primarily in its purpose and the nature of computations. While the backward pass focuses on computing the value function by iterating from the terminal state back to the initial state to form optimal policies, the forward pass applies these computed policies, iterating forward from the initial state to simulate the optimal trajectory. The purpose of the forward pass is to apply the control policies derived from the backward pass to ensure they achieve the expected outcomes in terms of state advancement and cost minimization. This is crucial for verifying the solution's feasibility and efficacy in real system dynamics after deriving theoretically optimal strategies .
The cost-to-go function, denoted as Vk(x), represents the minimum cost from stage k to the terminal stage N, inclusive of x. This function is crucial in dynamic programming as it determines the optimal policy by evaluating the impact of current decisions on future costs. Near the nominal trajectory, the cost-to-go function is approximated as locally quadratic, which simplifies the optimization process. Specifically, it is expanded as Vk(x) ≈ V(xk) + ∂V/∂x (x − xk) + 1/2 (x − xk)^T ∂^2V/∂x^2 (x − xk), enabling efficient computation of the necessary derivatives involved in the optimization .