Skip to content

Commit 20e854d

Browse files
committed
changed: renamed x0 to x̂d in nonlinear eq. constraints
This is clearer: it's the prediction of the deterministic states (in opposition to the state of the stochastic model of the unmeasured disturbances). It also equals the deviation vector of the model state `x0`, but using a "d" and a "hat" is clearer in this specific context.
1 parent 6723130 commit 20e854d

1 file changed

Lines changed: 40 additions & 43 deletions

File tree

src/controller/transcription.jl

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,14 +1406,14 @@ Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`]
14061406
The method mutates the `geq`, `X̂0`, `Û0` and `K` vectors in argument. The defects of the
14071407
stochastic states are linear equality constraints (see [`init_defectmat`](@ref)). The
14081408
defects of the deterministic states are computed with:
1409-
with:
14101409
```math
1411-
\mathbf{ŝ_d}(k+j+1) = \mathbf{f}\Big(\mathbf{x_0}(k+j), \mathbf{û_0}(k+j), \mathbf{d̂_0}(k+j)\Big)
1412-
- \mathbf{x_0}(k+j+1)
1410+
\mathbf{ŝ_d}(k+j+1) = \mathbf{f}\Big(\mathbf{x̂_d}(k+j), \mathbf{û_0}(k+j), \mathbf{d̂_0}(k+j)\Big)
1411+
- \mathbf{x̂_d}(k+j+1)
14131412
```
1414-
for ``j = 0, 1, ... , H_p-1``, and in which the deterministic state ``\mathbf{x_0}`` are
1415-
extracted from the decision variables `Z̃`, ``\mathbf{f}`` is the deterministic state update
1416-
function [`f!`](@ref), the disturbed input ``\mathbf{û_0}`` is defined in [`f̂!`](@ref)
1413+
for ``j = 0, 1, ... , H_p-1`` and in which the deterministic state ``\mathbf{x̂_d}`` are the
1414+
first `model.nx` elements of the augmented states ``\mathbf{x̂_0}, and they extracted from
1415+
the decision variables `Z̃`. The function ``\mathbf{f}`` is the deterministic state update
1416+
function [`f!`](@ref). The disturbed input ``\mathbf{û_0}`` is defined in [`f̂!`](@ref)
14171417
documentation. The defects of the stochastic states are linear equality constraints (see
14181418
[`init_defectmat`](@ref)).
14191419
"""
@@ -1431,19 +1431,19 @@ function con_nonlinprogeq!(
14311431
disturbedinput!(Û0, mpc, mpc.estim, U0, X̂0_Z̃)
14321432
@threadsif f_threads for j=1:Hp
14331433
if j < 2
1434-
x0_Z̃ = @views mpc.estim.x̂0[1:nx]
1434+
x̂d_Z̃ = @views mpc.estim.x̂0[1:nx]
14351435
d̂0 = @views mpc.d0[1:nd]
14361436
else
1437-
x0_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx + nx̂*(j-2))]
1437+
x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx̂*(j-2) + nx)]
14381438
d̂0 = @views D̂0[(1 + nd*(j-2)):(nd*(j-1))]
14391439
end
14401440
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
14411441
k = @views K[(1 + nk*(j-1)):(nk*j)]
1442-
x0next = @views X̂0[(1 + nx̂*(j-1)):(nx + nx̂*(j-1))]
1443-
x0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx + nx̂*(j-1))]
1442+
x̂dnext = @views X̂0[(1 + nx̂*(j-1)):(nx̂*(j-1) + nx)]
1443+
x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*(j-1) + nx)]
14441444
sdnext = @views geq[(1 + nx*(j-1)):(nx*j)]
1445-
f!(x0next, k, model, x0_Z̃, û0, d̂0, model.p)
1446-
sdnext .= @. x0next - x0next_Z̃
1445+
f!(x̂dnext, k, model, x̂d_Z̃, û0, d̂0, model.p)
1446+
sdnext .= @. x̂dnext - x̂dnext_Z̃
14471447
end
14481448
return geq
14491449
end
@@ -1459,23 +1459,23 @@ Nonlinear equality constrains for [`NonLinModel`](@ref) and [`TrapezoidalColloca
14591459
14601460
The deterministic state defects are computed with:
14611461
```math
1462-
\mathbf{s_d}(k+j+1) = \mathbf{x_0}(k+j) + 0.5 T_s [\mathbf{k̇}_1(k+j) + \mathbf{k̇}_2(k+j)]
1463-
- \mathbf{x_0}(k+j+1)
1462+
\mathbf{ŝ_d}(k+j+1) = \mathbf{x̂_d}(k+j) + 0.5 T_s [\mathbf{k̇}_1(k+j) + \mathbf{k̇}_2(k+j)]
1463+
- \mathbf{x̂_d}(k+j+1)
14641464
```
1465-
for ``j = 0, 1, ... , H_p-1``, and in which ``\mathbf{x_0}`` is the deterministic state
1465+
for ``j = 0, 1, ... , H_p-1``, and in which ``\mathbf{x̂_d}`` are the deterministic states
14661466
extracted from the decision variables `Z̃`. The ``\mathbf{k̇}`` coefficients are evaluated
14671467
from the continuous-time function `model.f!` and:
14681468
```math
14691469
\begin{aligned}
1470-
\mathbf{k̇}_1(k+j) &= \mathbf{f}\Big(\mathbf{x_0}(k+j), \mathbf{û_0}(k+j), \mathbf{d̂_0}(k+j), \mathbf{p}\Big) \\
1471-
\mathbf{k̇}_2(k+j) &= \mathbf{f}\Big(\mathbf{x_0}(k+j+1), \mathbf{û_0}(k+j+h), \mathbf{d̂_0}(k+j+1), \mathbf{p}\Big)
1470+
\mathbf{k̇}_1(k+j) &= \mathbf{f}\Big(\mathbf{x̂_d}(k+j), \mathbf{û_0}(k+j), \mathbf{d̂_0}(k+j), \mathbf{p}\Big) \\
1471+
\mathbf{k̇}_2(k+j) &= \mathbf{f}\Big(\mathbf{x̂_d}(k+j+1), \mathbf{û_0}(k+j+h), \mathbf{d̂_0}(k+j+1), \mathbf{p}\Big)
14721472
\end{aligned}
14731473
```
14741474
in which ``h`` is the hold order `transcription.h` and the disturbed input ``\mathbf{û_0}``
14751475
is defined in [`f̂!`](@ref) documentation.
14761476
"""
14771477
function con_nonlinprogeq!(
1478-
geq, X̂0, Û0, K̇,
1478+
geq, _ , Û0, K̇,
14791479
mpc::PredictiveController, model::NonLinModel, transcription::TrapezoidalCollocation,
14801480
U0, Z̃
14811481
)
@@ -1490,35 +1490,33 @@ function con_nonlinprogeq!(
14901490
disturbedinput!(Û0, mpc, mpc.estim, U0, X̂0_Z̃)
14911491
@threadsif f_threads for j=1:Hp
14921492
if j < 2
1493-
x̂0_Z̃ = @views mpc.estim.x̂0[1:nx̂]
1493+
x̂d_Z̃ = @views mpc.estim.x̂0[1:nx]
14941494
d̂0 = @views mpc.d0[1:nd]
14951495
else
1496-
x̂0_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx̂*(j-1))]
1496+
x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx̂*(j-2) + nx)]
14971497
d̂0 = @views D̂0[(1 + nd*(j-2)):(nd*(j-1))]
14981498
end
14991499
= @views K̇[(1 + nk*(j-1)):(nk*j)]
15001500
d̂0next = @views D̂0[(1 + nd*(j-1)):(nd*j)]
1501-
x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
1502-
sdnext = @views geq[(1 + nx*(j-1) ):(nx*(j-1) + nx)]
1503-
x0_Z̃ = @views x̂0_Z̃[1:nx]
1504-
x0next_Z̃ = @views x̂0next_Z̃[1:nx]
1501+
x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*(j-1) + nx)]
1502+
sdnext = @views geq[(1 + nx*(j-1)):(nx*(j-1) + nx)]
15051503
k̇1, k̇2 = @views k̇[1:nx], k̇[nx+1:2*nx]
15061504
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
15071505
if f_threads || h < 1 || j < 2
15081506
# we need to recompute k1 with multi-threading, even with h==1, since the
15091507
# last iteration (j-1) may not be executed (iterations are re-orderable)
1510-
model.f!(k̇1, x0_Z̃, û0, d̂0, p)
1508+
model.f!(k̇1, x̂d_Z̃, û0, d̂0, p)
15111509
else
15121510
k̇1 .= @views K̇[(1 + nk*(j-1)-nx):(nk*(j-1))] # k2 of of the last iter. j-1
15131511
end
15141512
if h < 1
1515-
model.f!(k̇2, x0next_Z̃, û0, d̂0next, p)
1513+
model.f!(k̇2, x̂dnext_Z̃, û0, d̂0next, p)
15161514
else
15171515
# j = Hp special case: u(k+Hp-1) = u(k+Hp) since Hc≤Hp implies Δu(k+Hp) = 0:
15181516
û0next = @views j Hp ? û0 : Û0[(1 + nu*j):(nu*(j+1))]
1519-
model.f!(k̇2, x0next_Z̃, û0next, d̂0next, p)
1517+
model.f!(k̇2, x̂dnext_Z̃, û0next, d̂0next, p)
15201518
end
1521-
sdnext .= @. x0_Z̃ - x0next_Z̃ + 0.5*Ts*(k̇1 + k̇2)
1519+
sdnext .= @. x̂d_Z̃ - x̂dnext_Z̃ + 0.5*Ts*(k̇1 + k̇2)
15221520
end
15231521
return geq
15241522
end
@@ -1538,20 +1536,21 @@ the model dynamics are computed by:
15381536
```math
15391537
\mathbf{s_k}(k+j)
15401538
= \mathbf{M_o} \begin{bmatrix}
1541-
\mathbf{k}_1(k+j) - \mathbf{x_0}(k+j) \\
1542-
\mathbf{k}_2(k+j) - \mathbf{x_0}(k+j) \\
1539+
\mathbf{k}_1(k+j) - \mathbf{x̂_d}(k+j) \\
1540+
\mathbf{k}_2(k+j) - \mathbf{x̂_d}(k+j) \\
15431541
\vdots \\
1544-
\mathbf{k}_{n_o}(k+j) - \mathbf{x_0}(k+j) \\ \end{bmatrix}
1542+
\mathbf{k}_{n_o}(k+j) - \mathbf{x̂_d}(k+j) \end{bmatrix}
15451543
- \begin{bmatrix}
15461544
\mathbf{k̇}_1(k+j) \\
15471545
\mathbf{k̇}_2(k+j) \\
15481546
\vdots \\
15491547
\mathbf{k̇}_{n_o}(k+j) \end{bmatrix}
15501548
```
15511549
for ``j = 0, 1, ... , H_p-1``, and knowing that the ``\mathbf{k}_i(k+j)`` vectors are
1552-
extracted from the decision variable `Z̃`. The ``\mathbf{x_0}`` vectors are the
1553-
deterministic state extracted from `Z̃`. The ``\mathbf{k̇}_i`` derivative for the ``i``th
1554-
collocation point is computed from the continuous-time function `model.f!` and:
1550+
extracted from the decision variable `Z̃`. The ``\mathbf{x̂_d}`` vectors are the
1551+
deterministic states extracted from ``\mathbf{X̂_̂0}`` in the decision vector `Z̃`. The
1552+
``\mathbf{k̇}_i`` derivative for the ``i``th collocation point is computed from the
1553+
continuous-time function `model.f!` and:
15551554
```math
15561555
\mathbf{k̇}_i(k+j) = \mathbf{f}\Big(\mathbf{k}_i(k+j), \mathbf{û_i}(k+j), \mathbf{d̂}_i(k+j), \mathbf{p}\Big)
15571556
```
@@ -1575,10 +1574,10 @@ ones for the continuity constraint of the deterministic states are:
15751574
\mathbf{k}_2(k+j) \\
15761575
\vdots \\
15771576
\mathbf{k}_{n_o}(k+j) \end{bmatrix}
1578-
+ λ_o \mathbf{x_0}(k+j) - \mathbf{x_0}(k+j+1)
1577+
+ λ_o \mathbf{x̂_d}(k+j) - \mathbf{x̂_d}(k+j+1)
15791578
```
15801579
for ``j = 0, 1, ... , H_p-1``. The differentiation matrix ``\mathbf{M_o}``, the continuity
1581-
matrix ``\mathbf{C_o}`` and the coefficient ``λ_o`` are introduced in [`init_orthocolloc`](@ref).
1580+
matrix ``\mathbf{C_o}`` and the coefficient ``λ_o`` are introduced in [`init_orthocolloc`](@ref).
15821581
"""
15831582
function con_nonlinprogeq!(
15841583
geq, _ , Û0, K̇,
@@ -1600,25 +1599,23 @@ function con_nonlinprogeq!(
16001599
disturbedinput!(Û0, mpc, mpc.estim, U0, X̂0_Z̃)
16011600
@threadsif f_threads for j=1:Hp
16021601
if j < 2
1603-
x̂0_Z̃ = @views mpc.estim.x̂0[1:nx̂]
1602+
x̂d_Z̃ = @views mpc.estim.x̂0[1:nx]
16041603
d̂0 = @views mpc.d0[1:nd]
16051604
else
1606-
x̂0_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx̂*(j-1))]
1605+
x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-2)):(nx̂*(j-2) + nx)]
16071606
d̂0 = @views D̂0[(1 + nd*(j-2)):(nd*(j-1))]
16081607
end
16091608
= @views K̇[(1 + nk*(j-1)):(nk*j)]
16101609
k_Z̃ = @views K_Z̃[(1 + nk*(j-1)):(nk*j)]
16111610
d̂0next = @views D̂0[(1 + nd*(j-1)):(nd*j)]
1612-
x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
1611+
x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*(j-1) + nx)]
16131612
scnext = @views geq[(1 + nx_nk*(j-1) ):(nx_nk*(j-1) + nx)]
16141613
sk = @views geq[(1 + nx_nk*(j-1) + nx):(nx_nk*j )]
1615-
x0_Z̃ = @views x̂0_Z̃[1:nx]
1616-
x0next_Z̃ = @views x̂0next_Z̃[1:nx]
16171614
# ----------------- collocation constraint defects -----------------------------
16181615
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
16191616
Δk =
16201617
for i=1:no
1621-
Δk[(1 + (i-1)*nx):(i*nx)] = @views k_Z̃[(1 + (i-1)*nx):(i*nx)] .- x0_Z̃
1618+
Δk[(1 + (i-1)*nx):(i*nx)] = @views k_Z̃[(1 + (i-1)*nx):(i*nx)] .- x̂d_Z̃
16221619
end
16231620
mul!(sk, Mo, Δk)
16241621
d̂i = @views D̂temp[(1 + nd*(j-1)):(nd*j)]
@@ -1640,7 +1637,7 @@ function con_nonlinprogeq!(
16401637
end
16411638
sk .-=
16421639
# ----------------- continuity constraint defects ------------------------------
1643-
scnext .= mul!(scnext, Co, k_Z̃) .+ (λo.*x0_Z̃) .- x0next_Z̃
1640+
scnext .= mul!(scnext, Co, k_Z̃) .+ (λo.*x̂d_Z̃) .- x̂dnext_Z̃
16441641
end
16451642
return geq
16461643
end

0 commit comments

Comments
 (0)