Skip to content

Commit e6ba1ef

Browse files
committed
changed: rename conversion matrices to avoid confusion with defect vector
1 parent 91b8d46 commit e6ba1ef

File tree

6 files changed

+130
-131
lines changed

6 files changed

+130
-131
lines changed

src/controller/construct.jl

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
struct PredictiveControllerBuffer{NT<:Real}
2-
u::Vector{NT}
3-
::Vector{NT}
4-
::Vector{NT}
5-
::Vector{NT}
6-
U::Vector{NT}
7-
::Matrix{NT}
8-
::Matrix{NT}
2+
u ::Vector{NT}
3+
::Vector{NT}
4+
::Vector{NT}
5+
::Vector{NT}
6+
U ::Vector{NT}
7+
::Matrix{NT}
8+
P̃U::Matrix{NT}
99
empty::Vector{NT}
1010
end
1111

@@ -21,15 +21,15 @@ function PredictiveControllerBuffer(
2121
) where NT <: Real
2222
nu, ny, nd, nx̂ = estim.model.nu, estim.model.ny, estim.model.nd, estim.nx̂
2323
nZ̃ = get_nZ(estim, transcription, Hp, Hc) +
24-
u = Vector{NT}(undef, nu)
25-
= Vector{NT}(undef, nZ̃)
26-
= Vector{NT}(undef, nd*Hp)
27-
= Vector{NT}(undef, ny*Hp)
28-
U = Vector{NT}(undef, nu*Hp)
29-
= Matrix{NT}(undef, ny*Hp, nZ̃)
30-
= Matrix{NT}(undef, nu*Hp, nZ̃)
24+
u = Vector{NT}(undef, nu)
25+
= Vector{NT}(undef, nZ̃)
26+
= Vector{NT}(undef, nd*Hp)
27+
= Vector{NT}(undef, ny*Hp)
28+
U = Vector{NT}(undef, nu*Hp)
29+
= Matrix{NT}(undef, ny*Hp, nZ̃)
30+
P̃U = Matrix{NT}(undef, nu*Hp, nZ̃)
3131
empty = Vector{NT}(undef, 0)
32-
return PredictiveControllerBuffer{NT}(u, Z̃, D̂, Ŷ, U, Ẽ, , empty)
32+
return PredictiveControllerBuffer{NT}(u, Z̃, D̂, Ŷ, U, Ẽ, P̃U, empty)
3333
end
3434

3535
"Include all the objective function weights of [`PredictiveController`](@ref)"
@@ -526,7 +526,7 @@ function validate_args(mpc::PredictiveController, ry, d, D̂, R̂y, R̂u)
526526
end
527527

528528
@doc raw"""
529-
init_quadprog(model::LinModel, weights::ControllerWeights, Ẽ, P̃, S̃) -> H̃
529+
init_quadprog(model::LinModel, weights::ControllerWeights, Ẽ, P̃ΔU, P̃U) -> H̃
530530
531531
Init the quadratic programming Hessian `H̃` for MPC.
532532
@@ -536,17 +536,17 @@ The matrix appear in the quadratic general form:
536536
```
537537
The Hessian matrix is constant if the model and weights are linear and time invariant (LTI):
538538
```math
539-
\mathbf{H̃} = 2 ( \mathbf{Ẽ}'\mathbf{M}_{H_p}\mathbf{Ẽ}
540-
+ \mathbf{P̃}'\mathbf{Ñ}_{H_c}\mathbf{}
541-
+ \mathbf{S̃}'\mathbf{L}_{H_p}\mathbf{S̃} )
539+
\mathbf{H̃} = 2 ( \mathbf{Ẽ}' \mathbf{M}_{H_p} \mathbf{Ẽ}
540+
+ \mathbf{P̃_{ΔU}}' \mathbf{Ñ}_{H_c} \mathbf{P̃_{ΔU}}
541+
+ \mathbf{P̃_{U}}' \mathbf{L}_{H_p} \mathbf{P̃_{U}} )
542542
```
543543
The vector ``\mathbf{q̃}`` and scalar ``r`` need recalculation each control period ``k``, see
544544
[`initpred!`](@ref). ``r`` does not impact the minima position. It is thus useless at
545545
optimization but required to evaluate the minimal ``J`` value.
546546
"""
547-
function init_quadprog(::LinModel, weights::ControllerWeights, Ẽ, P̃, S̃)
547+
function init_quadprog(::LinModel, weights::ControllerWeights, Ẽ, P̃ΔU, P̃U)
548548
M_Hp, Ñ_Hc, L_Hp = weights.M_Hp, weights.Ñ_Hc, weights.L_Hp
549-
= Hermitian(2*(Ẽ'*M_Hp*+ '*Ñ_Hc* + '*L_Hp*), :L)
549+
= Hermitian(2*(Ẽ'*M_Hp*+ P̃ΔU'*Ñ_Hc*P̃ΔU + P̃U'*L_Hp*P̃U), :L)
550550
return
551551
end
552552
"Return empty matrix if `model` is not a [`LinModel`](@ref)."
@@ -559,20 +559,20 @@ end
559559
init_defaultcon_mpc(
560560
estim::StateEstimator, transcription::TranscriptionMethod,
561561
Hp, Hc, C,
562-
P, S, E,
562+
PΔU, PU, E,
563563
ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
564564
Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
565565
gc!=nothing, nc=0
566-
) -> con, , Ẽ, Ẽŝ
566+
) -> con, nϵ, P̃ΔU, P̃U, Ẽ, Ẽŝ
567567
568568
Init `ControllerConstraint` struct with default parameters based on estimator `estim`.
569569
570-
Also return ``, ``, `Ẽ` and `Ẽŝ` matrices for the the augmented decision vector `Z̃`.
570+
Also return `P̃ΔU`, `P̃U`, `Ẽ` and `Ẽŝ` matrices for the the augmented decision vector `Z̃`.
571571
"""
572572
function init_defaultcon_mpc(
573573
estim::StateEstimator{NT}, transcription::TranscriptionMethod,
574-
Hp, Hc, C,
575-
P, S, E,
574+
Hp, Hc, C,
575+
PΔU, PU, E,
576576
ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
577577
Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
578578
gc!::GCfunc = nothing, nc = 0
@@ -592,8 +592,8 @@ function init_defaultcon_mpc(
592592
repeat_constraints(Hp, Hc, u0min, u0max, Δumin, Δumax, y0min, y0max)
593593
C_umin, C_umax, C_Δumin, C_Δumax, C_ymin, C_ymax =
594594
repeat_constraints(Hp, Hc, c_umin, c_umax, c_Δumin, c_Δumax, c_ymin, c_ymax)
595-
A_Umin, A_Umax, = relaxU(S, C_umin, C_umax, nϵ)
596-
A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, = relaxΔU(P, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ)
595+
A_Umin, A_Umax, P̃U = relaxU(PU, C_umin, C_umax, nϵ)
596+
A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU = relaxΔU(PΔU, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ)
597597
A_Ymin, A_Ymax, Ẽ = relaxŶ(E, C_ymin, C_ymax, nϵ)
598598
A_x̂min, A_x̂max, ẽx̂ = relaxterminal(ex̂, c_x̂min, c_x̂max, nϵ)
599599
A_ŝ, Ẽŝ = augmentdefect(Eŝ, nϵ)
@@ -620,7 +620,7 @@ function init_defaultcon_mpc(
620620
C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
621621
gc! , nc
622622
)
623-
return con, nϵ, P̃, S̃, Ẽ, Ẽŝ
623+
return con, nϵ, P̃ΔU, P̃U, Ẽ, Ẽŝ
624624
end
625625

626626
"Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
@@ -635,13 +635,13 @@ function repeat_constraints(Hp, Hc, umin, umax, Δumin, Δumax, ymin, ymax)
635635
end
636636

637637
@doc raw"""
638-
relaxU(S, C_umin, C_umax, nϵ) -> A_Umin, A_Umax,
638+
relaxU(PU, C_umin, C_umax, nϵ) -> A_Umin, A_Umax, P̃U
639639
640640
Augment manipulated inputs constraints with slack variable ϵ for softening.
641641
642642
Denoting the decision variables augmented with the slack variable
643643
``\mathbf{Z̃} = [\begin{smallmatrix} \mathbf{Z} \\ ϵ \end{smallmatrix}]``, it returns the
644-
augmented conversion matrix ``\mathbf{}``, similar to the one described at
644+
augmented conversion matrix ``\mathbf{P̃U}``, similar to the one described at
645645
[`init_ZtoU`](@ref). It also returns the ``\mathbf{A}`` matrices for the inequality
646646
constraints:
647647
```math
@@ -650,36 +650,36 @@ constraints:
650650
\mathbf{A_{U_{max}}}
651651
\end{bmatrix} \mathbf{Z̃} ≤
652652
\begin{bmatrix}
653-
- \mathbf{U_{min} + T u}(k-1) \\
654-
+ \mathbf{U_{max} - T u}(k-1)
653+
- \mathbf{U_{min} + T_U u}(k-1) \\
654+
+ \mathbf{U_{max} - T_U u}(k-1)
655655
\end{bmatrix}
656656
```
657657
in which ``\mathbf{U_{min}}`` and ``\mathbf{U_{max}}`` vectors respectively contains
658658
``\mathbf{u_{min}}`` and ``\mathbf{u_{max}}`` repeated ``H_p`` times.
659659
"""
660-
function relaxU(S::Matrix{NT}, C_umin, C_umax, nϵ) where NT<:Real
660+
function relaxU(PU::Matrix{NT}, C_umin, C_umax, nϵ) where NT<:Real
661661
if== 1 # Z̃ = [Z; ϵ]
662662
# ϵ impacts Z → U conversion for constraint calculations:
663-
A_Umin, A_Umax = -[S C_umin], [S -C_umax]
663+
A_Umin, A_Umax = -[PU C_umin], [PU -C_umax]
664664
# ϵ has no impact on Z → U conversion for prediction calculations:
665-
= [S zeros(NT, size(S, 1))]
665+
P̃U = [PU zeros(NT, size(PU, 1))]
666666
else # Z̃ = Z (only hard constraints)
667-
A_Umin, A_Umax = -S, S
668-
= S
667+
A_Umin, A_Umax = -PU, PU
668+
P̃U = PU
669669
end
670-
return A_Umin, A_Umax,
670+
return A_Umin, A_Umax, P̃U
671671
end
672672

673673
@doc raw"""
674-
relaxΔU(P, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax,
674+
relaxΔU(PΔU, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU
675675
676676
Augment input increments constraints with slack variable ϵ for softening.
677677
678678
Denoting the decision variables augmented with the slack variable
679679
``\mathbf{Z̃} = [\begin{smallmatrix} \mathbf{Z} \\ ϵ \end{smallmatrix}]``, it returns the
680-
augmented conversion matrix ``\mathbf{}``, similar to the one described at
680+
augmented conversion matrix ``\mathbf{P̃_{ΔU}}``, similar to the one described at
681681
[`init_ZtoΔU`](@ref), but extracting the input increments augmented with the slack variable
682-
``\mathbf{ΔŨ} = [\begin{smallmatrix} \mathbf{ΔU} \\ ϵ \end{smallmatrix}] = \mathbf{ Z̃}``.
682+
``\mathbf{ΔŨ} = [\begin{smallmatrix} \mathbf{ΔU} \\ ϵ \end{smallmatrix}] = \mathbf{P̃_{ΔU} Z̃}``.
683683
Also, knowing that ``0 ≤ ϵ ≤ ∞``, it also returns the augmented bounds
684684
``\mathbf{ΔŨ_{min}} = [\begin{smallmatrix} \mathbf{ΔU_{min}} \\ 0 \end{smallmatrix}]`` and
685685
``\mathbf{ΔŨ_{max}} = [\begin{smallmatrix} \mathbf{ΔU_{min}} \\\end{smallmatrix}]``,
@@ -695,23 +695,23 @@ and the ``\mathbf{A}`` matrices for the inequality constraints:
695695
\end{bmatrix}
696696
```
697697
Note that strictly speaking, the lower bound on the slack variable ϵ is a decision variable
698-
bound, which is more specific than a linear inequality constraint. However, it is more
698+
bound, which is more precise than a linear inequality constraint. However, it is more
699699
convenient to treat it as a linear inequality constraint since the optimizer `OSQP.jl` does
700700
not support pure bounds on the decision variables.
701701
"""
702-
function relaxΔU(P::Matrix{NT}, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<:Real
703-
nZ = size(P, 2)
702+
function relaxΔU(PΔU::Matrix{NT}, C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<:Real
703+
nZ = size(PΔU, 2)
704704
if== 1 # Z̃ = [Z; ϵ]
705705
ΔŨmin, ΔŨmax = [ΔUmin; NT[0.0]], [ΔUmax; NT[Inf]] # 0 ≤ ϵ ≤ ∞
706706
A_ϵ = [zeros(NT, 1, nZ) NT[1.0]]
707-
A_ΔŨmin, A_ΔŨmax = -[P C_Δumin; A_ϵ], [P -C_Δumax; A_ϵ]
708-
= [P zeros(NT, size(P, 1), 1); zeros(NT, 1, size(P, 2)) NT[1.0]]
707+
A_ΔŨmin, A_ΔŨmax = -[PΔU C_Δumin; A_ϵ], [PΔU -C_Δumax; A_ϵ]
708+
P̃ΔU = [PΔU zeros(NT, size(PΔU, 1), 1); zeros(NT, 1, size(PΔU, 2)) NT[1.0]]
709709
else # Z̃ = Z (only hard constraints)
710710
ΔŨmin, ΔŨmax = ΔUmin, ΔUmax
711-
A_ΔŨmin, A_ΔŨmax = -P, P
712-
= P
711+
A_ΔŨmin, A_ΔŨmax = -PΔU, PΔU
712+
P̃ΔU = PΔU
713713
end
714-
return A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax,
714+
return A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU
715715
end
716716

717717
@doc raw"""

src/controller/execute.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
128128
ΔŨ, Ŷe, Ue = nonlinprog_vectors!(ΔŨ, Ŷe, Ue, Ū, mpc, Ŷ0, Z̃)
129129
J = obj_nonlinprog!(Ȳ, Ū, mpc, model, Ue, Ŷe, ΔŨ, Z̃)
130130
U, Ŷ = Ū, Ȳ
131-
U .= mul!(U, mpc., mpc.Z̃) .+ mpc.T_lastu
131+
U .= mul!(U, mpc.P̃U, mpc.Z̃) .+ mpc.TU_lastu
132132
Ŷ .= Ŷ0 .+ mpc.Yop
133133
predictstoch!(Ŷs, mpc, mpc.estim)
134134
info[:ΔU] = Z̃[1:mpc.Hc*model.nu]
@@ -181,8 +181,8 @@ They are computed with these equations using in-place operations:
181181
+ \mathbf{V u_0}(k-1) + \mathbf{B} + \mathbf{Ŷ_s} \\
182182
\mathbf{C_y} &= \mathbf{F} + \mathbf{Y_{op}} - \mathbf{R̂_y} \\
183183
\mathbf{C_u} &= \mathbf{T}\mathbf{u}(k-1) - \mathbf{R̂_u} \\
184-
\mathbf{q̃} &= 2[ (\mathbf{M}_{H_p} \mathbf{Ẽ})' \mathbf{C_y}
185-
+ (\mathbf{L}_{H_p} \mathbf{})' \mathbf{C_u} ] \\
184+
\mathbf{q̃} &= 2[ (\mathbf{M}_{H_p} \mathbf{Ẽ})' \mathbf{C_y}
185+
+ (\mathbf{L}_{H_p} \mathbf{P̃_U})' \mathbf{C_u} ] \\
186186
r &= \mathbf{C_y}' \mathbf{M}_{H_p} \mathbf{C_y}
187187
+ \mathbf{C_u}' \mathbf{L}_{H_p} \mathbf{C_u}
188188
\end{aligned}
@@ -197,7 +197,7 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂
197197
mul!(F, mpc.G, mpc.d0, 1, 1) # F = F + G*d0
198198
mul!(F, mpc.J, mpc.D̂0, 1, 1) # F = F + J*D̂0
199199
end
200-
Cy, Cu, M_Hp_Ẽ, L_Hp_S̃ = mpc.buffer.Ŷ, mpc.buffer.U, mpc.buffer.Ẽ, mpc.buffer.
200+
Cy, Cu, M_Hp_Ẽ, L_Hp_P̃U = mpc.buffer.Ŷ, mpc.buffer.U, mpc.buffer.Ẽ, mpc.buffer.P̃U
201201
q̃, r = mpc.q̃, mpc.r
202202
q̃ .= 0
203203
r .= 0
@@ -210,9 +210,9 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂
210210
end
211211
# --- input setpoint tracking term ---
212212
if !mpc.weights.iszero_L_Hp[]
213-
Cu .= mpc.T_lastu .- R̂u
214-
mul!(L_Hp_S̃, mpc.weights.L_Hp, mpc.)
215-
mul!(q̃, L_Hp_S̃', Cu, 1, 1) # q̃ = q̃ + L_Hp*'*Cu
213+
Cu .= mpc.TU_lastu .- R̂u
214+
mul!(L_Hp_P̃U, mpc.weights.L_Hp, mpc.P̃U)
215+
mul!(q̃, L_Hp_P̃U', Cu, 1, 1) # q̃ = q̃ + L_Hp*P̃U'*Cu
216216
r .+= dot(Cu, mpc.weights.L_Hp, Cu) # r = r + Cu'*L_Hp*Cu
217217
end
218218
# --- finalize ---
@@ -241,7 +241,7 @@ is an [`InternalModel`](@ref). The function returns `mpc.F`.
241241
function initpred_common!(mpc::PredictiveController, model::SimModel, d, D̂, R̂y, R̂u)
242242
lastu = mpc.buffer.u
243243
lastu .= mpc.estim.lastu0 .+ model.uop
244-
mul!(mpc.T_lastu, mpc.T, lastu)
244+
mul!(mpc.TU_lastu, mpc.TU, lastu)
245245
mpc.ŷ .= evaloutput(mpc.estim, d)
246246
if model.nd 0
247247
mpc.d0 .= d .- model.dop
@@ -288,9 +288,9 @@ function linconstraint!(mpc::PredictiveController, model::LinModel)
288288
mul!(fx̂, mpc.con.jx̂, mpc.D̂0, 1, 1)
289289
end
290290
n = 0
291-
mpc.con.b[(n+1):(n+nU)] .= @. -mpc.con.U0min - mpc.Uop + mpc.T_lastu
291+
mpc.con.b[(n+1):(n+nU)] .= @. -mpc.con.U0min - mpc.Uop + mpc.TU_lastu
292292
n += nU
293-
mpc.con.b[(n+1):(n+nU)] .= @. +mpc.con.U0max + mpc.Uop - mpc.T_lastu
293+
mpc.con.b[(n+1):(n+nU)] .= @. +mpc.con.U0max + mpc.Uop - mpc.TU_lastu
294294
n += nU
295295
mpc.con.b[(n+1):(n+nΔŨ)] .= @. -mpc.con.ΔŨmin
296296
n += nΔŨ
@@ -314,9 +314,9 @@ end
314314
function linconstraint!(mpc::PredictiveController, ::SimModel)
315315
nU, nΔŨ = length(mpc.con.U0min), length(mpc.con.ΔŨmin)
316316
n = 0
317-
mpc.con.b[(n+1):(n+nU)] .= @. -mpc.con.U0min - mpc.Uop + mpc.T_lastu
317+
mpc.con.b[(n+1):(n+nU)] .= @. -mpc.con.U0min - mpc.Uop + mpc.TU_lastu
318318
n += nU
319-
mpc.con.b[(n+1):(n+nU)] .= @. +mpc.con.U0max + mpc.Uop - mpc.T_lastu
319+
mpc.con.b[(n+1):(n+nU)] .= @. +mpc.con.U0max + mpc.Uop - mpc.TU_lastu
320320
n += nU
321321
mpc.con.b[(n+1):(n+nΔŨ)] .= @. -mpc.con.ΔŨmin
322322
n += nΔŨ
@@ -351,7 +351,7 @@ function nonlinprog_vectors!(ΔŨ, Ŷe, Ue, Ū, mpc::PredictiveController, Y
351351
nocustomfcts = (mpc.weights.iszero_E && iszero_nc(mpc))
352352
# --- augmented input increments ΔŨ = [ΔU; ϵ] ---
353353
if !(mpc.weights.iszero_Ñ_Hc[])
354-
ΔŨ .= mul!(ΔŨ, mpc., Z̃)
354+
ΔŨ .= mul!(ΔŨ, mpc.P̃ΔU, Z̃)
355355
end
356356
# --- extended output predictions Ŷe = [ŷ(k); Ŷ] ---
357357
if !(mpc.weights.iszero_M_Hp[] && nocustomfcts)
@@ -361,7 +361,7 @@ function nonlinprog_vectors!(ΔŨ, Ŷe, Ue, Ū, mpc::PredictiveController, Y
361361
# --- extended manipulated inputs Ue = [U; u(k+Hp-1)] ---
362362
if !(mpc.weights.iszero_L_Hp[] && nocustomfcts)
363363
U =
364-
U .= mul!(U, mpc., Z̃) .+ mpc.T_lastu
364+
U .= mul!(U, mpc.P̃U, Z̃) .+ mpc.TU_lastu
365365
Ue[1:end-nu] .= U
366366
# u(k + Hp) = u(k + Hp - 1) since Δu(k+Hp) = 0 (because Hc ≤ Hp):
367367
Ue[end-nu+1:end] .= @views U[end-nu+1:end]
@@ -719,7 +719,7 @@ function setmodel_controller!(mpc::PredictiveController, x̂op_old)
719719
JuMP.unregister(optim, :linconstrainteq)
720720
@constraint(optim, linconstrainteq, Aeq*Z̃var .== beq)
721721
# --- quadratic programming Hessian matrix ---
722-
= init_quadprog(model, mpc.weights, mpc.Ẽ, mpc., mpc.)
722+
= init_quadprog(model, mpc.weights, mpc.Ẽ, mpc.P̃ΔU, mpc.P̃U)
723723
mpc.H̃ .=
724724
set_objective_hessian!(mpc, Z̃var)
725725
return nothing

src/controller/explicitmpc.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
99
weights::ControllerWeights{NT}
1010
R̂u::Vector{NT}
1111
R̂y::Vector{NT}
12-
::Matrix{NT}
13-
::Matrix{NT}
14-
T::Matrix{NT}
15-
T_lastu::Vector{NT}
12+
P̃ΔU::Matrix{NT}
13+
P̃U ::Matrix{NT}
14+
TU ::Matrix{NT}
15+
TU_lastu::Vector{NT}
1616
::Matrix{NT}
1717
F::Vector{NT}
1818
G::Matrix{NT}
@@ -46,15 +46,15 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
4646
N_Hc = Hermitian(convert(Matrix{NT}, N_Hc), :L)
4747
L_Hp = Hermitian(convert(Matrix{NT}, L_Hp), :L)
4848
# dummy vals (updated just before optimization):
49-
R̂y, R̂u, T_lastu = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
49+
R̂y, R̂u, TU_lastu = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
5050
transcription = SingleShooting() # explicit MPC only supports SingleShooting
51-
P = init_ZtoΔU(estim, transcription, Hp, Hc)
52-
S, T = init_ZtoU(estim, transcription, Hp, Hc)
51+
PΔU = init_ZtoΔU(estim, transcription, Hp, Hc)
52+
PU, TU = init_ZtoU(estim, transcription, Hp, Hc)
5353
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
5454
# dummy val (updated just before optimization):
5555
F, fx̂ = zeros(NT, ny*Hp), zeros(NT, nx̂)
56-
P̃, S̃, Ñ_Hc, Ẽ = P, S, N_Hc, E # no slack variable ϵ for ExplicitMPC
57-
= init_quadprog(model, weights, Ẽ, P̃, S̃)
56+
P̃ΔU, P̃U, Ñ_Hc, Ẽ = PΔU, PU, N_Hc, E # no slack variable ϵ for ExplicitMPC
57+
= init_quadprog(model, weights, Ẽ, P̃ΔU, P̃U)
5858
# dummy vals (updated just before optimization):
5959
q̃, r = zeros(NT, size(H̃, 1)), zeros(NT, 1)
6060
H̃_chol = cholesky(H̃)
@@ -72,7 +72,7 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
7272
Hp, Hc, nϵ,
7373
weights,
7474
R̂u, R̂y,
75-
P̃, S̃, T, T_lastu,
75+
P̃ΔU, P̃U, TU, TU_lastu,
7676
Ẽ, F, G, J, K, V, B,
7777
H̃, q̃, r,
7878
H̃_chol,
@@ -225,7 +225,7 @@ function setmodel_controller!(mpc::ExplicitMPC, _ )
225225
mpc.V .= V
226226
mpc.B .= B
227227
# --- quadratic programming Hessian matrix ---
228-
= init_quadprog(model, mpc.weights, mpc.Ẽ, mpc., mpc.)
228+
= init_quadprog(model, mpc.weights, mpc.Ẽ, mpc.P̃ΔU, mpc.P̃U)
229229
mpc.H̃ .=
230230
set_objective_hessian!(mpc)
231231
# --- operating points ---

0 commit comments

Comments
 (0)