Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
142f0ad
doc: adding compat admonition for MTK example
franckgaga Dec 31, 2025
cf6931e
doc: correct prediction matrices for `LinModel` with move blocking
franckgaga Dec 31, 2025
799ba37
doc: correct terminal state prediction matrices for `LinModel`
franckgaga Dec 31, 2025
4cc02a3
changed: introducing `W(m)` function for clarity
franckgaga Dec 31, 2025
891156c
changed: similar function in `init_predmat_mhe`
franckgaga Dec 31, 2025
189b6ed
added: `Q!(Q, i, j)` function for move blocking
franckgaga Dec 31, 2025
8118bac
doc: minor modification
franckgaga Dec 31, 2025
0cc2589
doc: correct mistake on the last row of `E` matrix with move blocking
franckgaga Dec 31, 2025
04b1692
added: `nb` argument to `init_predmat`
franckgaga Dec 31, 2025
bd3600c
added: correct `E` matrix implemented for `LinModel`
franckgaga Jan 1, 2026
326ada4
debug: wip debug move blocking
franckgaga Jan 1, 2026
0bd1699
doc: new `j_ℓ` notation in `move_blocking`
franckgaga Jan 1, 2026
01d0410
doc: three arguments `Q` function in `init_predmat`
franckgaga Jan 1, 2026
441ad61
added: implementing new 3-args `Q!` function
franckgaga Jan 2, 2026
4f9277a
doc: minor correction
franckgaga Jan 2, 2026
e8ee153
changed: minor correction
franckgaga Jan 2, 2026
1a41588
changed: renamed `k` to `m` in `Q!` function
franckgaga Jan 2, 2026
2bb5b86
doc: debugged equations in `init_defectmat`
franckgaga Jan 2, 2026
6256694
debug: move blocking with `LinModel` and `MultipleShooting` works
franckgaga Jan 2, 2026
b38eec4
test: comparing move blocking results in all the cases
franckgaga Jan 2, 2026
65957c2
test: debug test
franckgaga Jan 2, 2026
7bb8e7e
doc: detail
franckgaga Jan 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ModelPredictiveControl"
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
version = "1.14.3"
version = "1.14.4"
authors = ["Francis Gagnon"]

[deps]
Expand Down
4 changes: 4 additions & 0 deletions docs/src/manual/mtk.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ the last section.
as a basic starting template to combine both packages. There is no guarantee that it
will work for all corner cases.

!!! compat
The example works on `ModelingToolkit.jl` v10 (corresponding to the following `[compat]`
entry: `ModelingToolkit = "10"`).

We first construct and instantiate the pendulum model:

```@example 1
Expand Down
13 changes: 7 additions & 6 deletions src/controller/construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,16 @@ strictly positive integers):
```math
\mathbf{n_b} = \begin{bmatrix} n_1 & n_2 & \cdots & n_{H_c} \end{bmatrix}'
```
The vector that includes all the manipulated input increments ``\mathbf{Δu}`` is then
Introducing the notation ``j_ℓ = ∑_{i=1}^{ℓ} n_i`` to convert from block lengths to discrete
time steps, the vector that includes all the free moves of the manipulated input is then
defined as:
```math
\mathbf{ΔU} = \begin{bmatrix}
\mathbf{Δu}(k + 0) \\[0.1em]
\mathbf{Δu}(k + ∑_{i=1}^1 n_i) \\[0.1em]
\mathbf{Δu}(k + ∑_{i=1}^2 n_i) \\[0.1em]
\vdots \\[0.1em]
\mathbf{Δu}(k + ∑_{i=1}^{H_c-1} n_i)
\mathbf{Δu}(k + 0) \\
\mathbf{Δu}(k + j_1) \\
\mathbf{Δu}(k + j_2) \\
\vdots \\
\mathbf{Δu}(k + j_{H_c-1})
\end{bmatrix}
```
The provided `nb` vector is modified to ensure `sum(nb) == Hp`:
Expand Down
6 changes: 3 additions & 3 deletions src/controller/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ end
function setmodel_controller!(mpc::PredictiveController, uop_old, x̂op_old)
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
weights = mpc.weights
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
optim, con = mpc.optim, mpc.con
# --- prediction matrices ---
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
model, estim, transcription, Hp, Hc
model, estim, transcription, Hp, Hc, nb
)
A_Ymin, A_Ymax, Ẽ = relaxŶ(E, con.C_ymin, con.C_ymax, mpc.nϵ)
A_x̂min, A_x̂max, ẽx̂ = relaxterminal(ex̂, con.c_x̂min, con.c_x̂max, mpc.nϵ)
Expand All @@ -639,7 +639,7 @@ function setmodel_controller!(mpc::PredictiveController, uop_old, x̂op_old)
mpc.V .= V
mpc.B .= B
# --- defect matrices ---
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
A_ŝ, Ẽŝ = augmentdefect(Eŝ, mpc.nϵ)
con.Ẽŝ .= Ẽŝ
con.Gŝ .= Gŝ
Expand Down
6 changes: 3 additions & 3 deletions src/controller/explicitmpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ExplicitMPC{
validate_transcription(model, transcription)
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
# dummy val (updated just before optimization):
F = zeros(NT, ny*Hp)
P̃Δu, P̃u, Ẽ = PΔu, Pu, E # no slack variable ϵ for ExplicitMPC
Expand Down Expand Up @@ -226,9 +226,9 @@ addinfo!(info, mpc::ExplicitMPC) = info
function setmodel_controller!(mpc::ExplicitMPC, uop_old, _ )
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
weights = mpc.weights
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
# --- predictions matrices ---
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
Ẽ = E # no slack variable ϵ for ExplicitMPC
mpc.Ẽ .= Ẽ
mpc.G .= G
Expand Down
4 changes: 2 additions & 2 deletions src/controller/linmpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ struct LinMPC{
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
model, estim, transcription, Hp, Hc
model, estim, transcription, Hp, Hc, nb
)
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
# dummy vals (updated just before optimization):
F, fx̂, Fŝ = zeros(NT, ny*Hp), zeros(NT, nx̂), zeros(NT, nx̂*Hp)
con, nϵ, P̃Δu, P̃u, Ẽ = init_defaultcon_mpc(
Expand Down
4 changes: 2 additions & 2 deletions src/controller/nonlinmpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ struct NonLinMPC{
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
model, estim, transcription, Hp, Hc
model, estim, transcription, Hp, Hc, nb
)
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc, nb)
# dummy vals (updated just before optimization):
F, fx̂, Fŝ = zeros(NT, ny*Hp), zeros(NT, nx̂), zeros(NT, nx̂*Hp)
con, nϵ, P̃Δu, P̃u, Ẽ = init_defaultcon_mpc(
Expand Down
Loading