Skip to content

Commit 80f6a52

Browse files
authored
Merge pull request #301 from JuliaControl/debug_moveblocking
debug: correctly handle custom move blocking for `LinModel`
2 parents 81b2f31 + 7bb8e7e commit 80f6a52

10 files changed

Lines changed: 175 additions & 82 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
3-
version = "1.14.3"
3+
version = "1.14.4"
44
authors = ["Francis Gagnon"]
55

66
[deps]

docs/src/manual/mtk.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ the last section.
2222
as a basic starting template to combine both packages. There is no guarantee that it
2323
will work for all corner cases.
2424

25+
!!! compat
26+
The example works on `ModelingToolkit.jl` v10 (corresponding to the following `[compat]`
27+
entry: `ModelingToolkit = "10"`).
28+
2529
We first construct and instantiate the pendulum model:
2630

2731
```@example 1

src/controller/construct.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,16 @@ strictly positive integers):
499499
```math
500500
\mathbf{n_b} = \begin{bmatrix} n_1 & n_2 & \cdots & n_{H_c} \end{bmatrix}'
501501
```
502-
The vector that includes all the manipulated input increments ``\mathbf{Δu}`` is then
502+
Introducing the notation ``j_ℓ = ∑_{i=1}^{ℓ} n_i`` to convert from block lengths to discrete
503+
time steps, the vector that includes all the free moves of the manipulated input is then
503504
defined as:
504505
```math
505506
\mathbf{ΔU} = \begin{bmatrix}
506-
\mathbf{Δu}(k + 0) \\[0.1em]
507-
\mathbf{Δu}(k + ∑_{i=1}^1 n_i) \\[0.1em]
508-
\mathbf{Δu}(k + ∑_{i=1}^2 n_i) \\[0.1em]
509-
\vdots \\[0.1em]
510-
\mathbf{Δu}(k + ∑_{i=1}^{H_c-1} n_i)
507+
\mathbf{Δu}(k + 0) \\
508+
\mathbf{Δu}(k + j_1) \\
509+
\mathbf{Δu}(k + j_2) \\
510+
\vdots \\
511+
\mathbf{Δu}(k + j_{H_c-1})
511512
\end{bmatrix}
512513
```
513514
The provided `nb` vector is modified to ensure `sum(nb) == Hp`:

src/controller/execute.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,11 @@ end
624624
function setmodel_controller!(mpc::PredictiveController, uop_old, x̂op_old)
625625
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
626626
weights = mpc.weights
627-
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
627+
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
628628
optim, con = mpc.optim, mpc.con
629629
# --- prediction matrices ---
630630
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
631-
model, estim, transcription, Hp, Hc
631+
model, estim, transcription, Hp, Hc, nb
632632
)
633633
A_Ymin, A_Ymax, Ẽ = relaxŶ(E, con.C_ymin, con.C_ymax, mpc.nϵ)
634634
A_x̂min, A_x̂max, ẽx̂ = relaxterminal(ex̂, con.c_x̂min, con.c_x̂max, mpc.nϵ)
@@ -639,7 +639,7 @@ function setmodel_controller!(mpc::PredictiveController, uop_old, x̂op_old)
639639
mpc.V .= V
640640
mpc.B .= B
641641
# --- defect matrices ---
642-
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
642+
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
643643
A_ŝ, Ẽŝ = augmentdefect(Eŝ, mpc.nϵ)
644644
con.Ẽŝ .= Ẽŝ
645645
con.Gŝ .= Gŝ

src/controller/explicitmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ExplicitMPC{
5353
validate_transcription(model, transcription)
5454
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
5555
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
56-
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
56+
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
5757
# dummy val (updated just before optimization):
5858
F = zeros(NT, ny*Hp)
5959
P̃Δu, P̃u, Ẽ = PΔu, Pu, E # no slack variable ϵ for ExplicitMPC
@@ -226,9 +226,9 @@ addinfo!(info, mpc::ExplicitMPC) = info
226226
function setmodel_controller!(mpc::ExplicitMPC, uop_old, _ )
227227
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
228228
weights = mpc.weights
229-
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
229+
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
230230
# --- predictions matrices ---
231-
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
231+
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
232232
= E # no slack variable ϵ for ExplicitMPC
233233
mpc.Ẽ .=
234234
mpc.G .= G

src/controller/linmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ struct LinMPC{
6767
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
6868
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
6969
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
70-
model, estim, transcription, Hp, Hc
70+
model, estim, transcription, Hp, Hc, nb
7171
)
72-
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
72+
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
7373
# dummy vals (updated just before optimization):
7474
F, fx̂, Fŝ = zeros(NT, ny*Hp), zeros(NT, nx̂), zeros(NT, nx̂*Hp)
7575
con, nϵ, P̃Δu, P̃u, Ẽ = init_defaultcon_mpc(

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ struct NonLinMPC{
9595
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
9696
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
9797
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
98-
model, estim, transcription, Hp, Hc
98+
model, estim, transcription, Hp, Hc, nb
9999
)
100-
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
100+
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
101101
# dummy vals (updated just before optimization):
102102
F, fx̂, Fŝ = zeros(NT, ny*Hp), zeros(NT, nx̂), zeros(NT, nx̂*Hp)
103103
con, nϵ, P̃Δu, P̃u, Ẽ = init_defaultcon_mpc(

0 commit comments

Comments
 (0)