Skip to content

Commit 3719df7

Browse files
committed
debug: Julia 1.6
1 parent d8f9b5c commit 3719df7

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

src/controller/explicitmpc.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ Construct an explicit linear predictive controller based on [`LinModel`](@ref) `
7979
8080
The controller minimizes the following objective function at each discrete time ``k``:
8181
```math
82-
\min_{\mathbf{ΔU}} \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
83-
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)}
84-
+ \mathbf{(R̂_u - U)}' \mathbf{L}_{H_p} \mathbf{(R̂_u - U)}
82+
\begin{aligned}
83+
\min_{\mathbf{ΔU}} \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
84+
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)} \\
85+
+ \mathbf{(R̂_u - U)}' \mathbf{L}_{H_p} \mathbf{(R̂_u - U)}
86+
\end{aligned}
8587
```
8688
8789
See [`LinMPC`](@ref) for the variable definitions. This controller does not support

src/controller/linmpc.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ Construct a linear predictive controller based on [`LinModel`](@ref) `model`.
8686
8787
The controller minimizes the following objective function at each discrete time ``k``:
8888
```math
89-
\min_{\mathbf{ΔU}, ϵ} \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
90-
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)}
91-
+ \mathbf{(R̂_u - U)}' \mathbf{L}_{H_p} \mathbf{(R̂_u - U)}
92-
+ C ϵ^2
89+
\begin{aligned}
90+
\min_{\mathbf{ΔU}, ϵ} \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
91+
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)} \\
92+
+ \mathbf{(R̂_u - U)}' \mathbf{L}_{H_p} \mathbf{(R̂_u - U)}
93+
+ C ϵ^2
94+
\end{aligned}
9395
```
9496
in which the weight matrices are repeated ``H_p`` or ``H_c`` times:
9597
```math

src/controller/nonlinmpc.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,22 @@ Construct a nonlinear predictive controller based on [`SimModel`](@ref) `model`.
8888
Both [`NonLinModel`](@ref) and [`LinModel`](@ref) are supported (see Extended Help). The
8989
controller minimizes the following objective function at each discrete time ``k``:
9090
```math
91-
\min_{\mathbf{ΔU}, ϵ} \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
92-
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)}
91+
\begin{aligned}
92+
\min_{\mathbf{ΔU}, ϵ}\ & \mathbf{(R̂_y - Ŷ)}' \mathbf{M}_{H_p} \mathbf{(R̂_y - Ŷ)}
93+
+ \mathbf{(ΔU)}' \mathbf{N}_{H_c} \mathbf{(ΔU)} \\&
9394
+ \mathbf{(R̂_u - U)}' \mathbf{L}_{H_p} \mathbf{(R̂_u - U)}
94-
+ C ϵ^2 + E J_E(\mathbf{U}_E, \mathbf{Ŷ}_E, \mathbf{D̂}_E)
95+
+ C ϵ^2
96+
+ E J_E(\mathbf{U}_E, \mathbf{Ŷ}_E, \mathbf{D̂}_E)
97+
\end{aligned}
9598
```
9699
See [`LinMPC`](@ref) for the variable definitions. The custom economic function ``J_E`` can
97100
penalizes solutions with high economic costs. Setting all the weights to 0 except ``E``
98101
creates a pure economic model predictive controller (EMPC). The arguments of ``J_E`` are
99102
the manipulated inputs, the predicted outputs and measured disturbances from ``k`` to
100103
``k+H_p`` inclusively:
101104
```math
102-
\mathbf{U}_E = \begin{bmatrix} \mathbf{U} \\ \mathbf{u}(k+H_p-1) \end{bmatrix} \text{,} \qquad
103-
\mathbf{Ŷ}_E = \begin{bmatrix} \mathbf{ŷ}(k) \\ \mathbf{Ŷ} \end{bmatrix} \text{,} \qquad
105+
\mathbf{U}_E = \begin{bmatrix} \mathbf{U} \\ \mathbf{u}(k+H_p-1) \end{bmatrix} , \quad
106+
\mathbf{Ŷ}_E = \begin{bmatrix} \mathbf{ŷ}(k) \\ \mathbf{Ŷ} \end{bmatrix} , \quad
104107
\mathbf{D̂}_E = \begin{bmatrix} \mathbf{d}(k) \\ \mathbf{D̂} \end{bmatrix}
105108
```
106109
since ``H_c ≤ H_p`` implies that ``\mathbf{Δu}(k+H_p) = \mathbf{0}`` or ``\mathbf{u}(k+H_p)=

src/estimator/kalman.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function SteadyKalmanFilter(
148148
σQint_ym::Vector = fill(1, max(sum(nint_ym), 0))
149149
) where {NT<:Real, SM<:LinModel{NT}}
150150
# estimated covariances matrices (variance = σ²) :
151-
= Diagonal{NT}([σQ; σQint_u; σQint_ym].^2)
152-
= Diagonal{NT}(σR.^2)
151+
= Hermitian(diagm(NT[σQ; σQint_u; σQint_ym ].^2), :L)
152+
= Hermitian(diagm(NT[σR;].^2), :L)
153153
return SteadyKalmanFilter{NT, SM}(model, i_ym, nint_u, nint_ym, Q̂ , R̂)
154154
end
155155

@@ -288,9 +288,9 @@ function KalmanFilter(
288288
σP0int_ym::Vector = σQint_ym,
289289
) where {NT<:Real, SM<:LinModel{NT}}
290290
# estimated covariances matrices (variance = σ²) :
291-
P̂0 = Diagonal{NT}([σP0; σP0int_u; σP0int_ym].^2)
292-
= Diagonal{NT}([σQ; σQint_u; σQint_ym].^2)
293-
= Diagonal{NT}(σR.^2)
291+
P̂0 = Hermitian(diagm(NT[σP0; σP0int_u; σP0int_ym].^2), :L)
292+
= Hermitian(diagm(NT[σQ; σQint_u; σQint_ym ].^2), :L)
293+
= Hermitian(diagm(NT[σR;].^2), :L)
294294
return KalmanFilter{NT, SM}(model, i_ym, nint_u, nint_ym, P̂0, Q̂ , R̂)
295295
end
296296

@@ -457,9 +457,9 @@ function UnscentedKalmanFilter(
457457
κ::Real = 0
458458
) where {NT<:Real, SM<:SimModel{NT}}
459459
# estimated covariances matrices (variance = σ²) :
460-
P̂0 = Diagonal{NT}([σP0; σP0int_u; σP0int_ym].^2)
461-
= Diagonal{NT}([σQ; σQint_u; σQint_ym].^2)
462-
= Diagonal{NT}(σR.^2)
460+
P̂0 = Hermitian(diagm(NT[σP0; σP0int_u; σP0int_ym].^2), :L)
461+
= Hermitian(diagm(NT[σQ; σQint_u; σQint_ym ].^2), :L)
462+
= Hermitian(diagm(NT[σR;].^2), :L)
463463
return UnscentedKalmanFilter{NT, SM}(model, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂, α, β, κ)
464464
end
465465

@@ -680,9 +680,9 @@ function ExtendedKalmanFilter(
680680
σP0int_ym::Vector = σQint_ym,
681681
) where {NT<:Real, SM<:SimModel{NT}}
682682
# estimated covariances matrices (variance = σ²) :
683-
P̂0 = Diagonal{NT}([σP0; σP0int_u; σP0int_ym].^2)
684-
= Diagonal{NT}([σQ; σQint_u; σQint_ym].^2)
685-
= Diagonal{NT}(σR.^2)
683+
P̂0 = Hermitian(diagm(NT[σP0; σP0int_u; σP0int_ym].^2), :L)
684+
= Hermitian(diagm(NT[σQ; σQint_u; σQint_ym ].^2), :L)
685+
= Hermitian(diagm(NT[σR;].^2), :L)
686686
return ExtendedKalmanFilter{NT, SM}(model, i_ym, nint_u, nint_ym, P̂0, Q̂ , R̂)
687687
end
688688

src/estimator/mhe.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ function MovingHorizonEstimator(
173173
optim::JM = JuMP.Model(DEFAULT_MHE_OPTIMIZER, add_bridges=false),
174174
) where {NT<:Real, SM<:SimModel{NT}, JM<:JuMP.GenericModel}
175175
# estimated covariances matrices (variance = σ²) :
176-
P̂0 = Diagonal{NT}([σP0; σP0int_u; σP0int_ym].^2)
177-
= Diagonal{NT}([σQ; σQint_u; σQint_ym].^2)
178-
= Diagonal{NT}(σR.^2)
176+
P̂0 = Hermitian(diagm(NT[σP0; σP0int_u; σP0int_ym].^2), :L)
177+
= Hermitian(diagm(NT[σQ; σQint_u; σQint_ym ].^2), :L)
178+
= Hermitian(diagm(NT[σR;].^2), :L)
179179
isnothing(He) && throw(ArgumentError("Estimation horizon He must be explicitly specified"))
180180
return MovingHorizonEstimator{NT, SM, JM}(
181181
model, He, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂, optim

src/precompile_calls.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ mpc_skf.estim()
4141
u = mpc_skf([55, 30])
4242
sim!(mpc_skf, 3, [55, 30])
4343

44+
mpc_mhe = setconstraint!(LinMPC(MovingHorizonEstimator(model, He=2)), ymin=[45, -Inf])
45+
setconstraint!(mpc_mhe.estim, x̂min=[-50,-50,-50,-50], x̂max=[50,50,50,50])
46+
initstate!(mpc_mhe, model.uop, model())
47+
mpc_mhe.estim()
48+
u = mpc_mhe([55, 30])
49+
sim!(mpc_mhe, 3, [55, 30])
50+
4451
nmpc_skf = setconstraint!(NonLinMPC(SteadyKalmanFilter(model), Cwt=Inf), ymin=[45, -Inf])
4552
initstate!(nmpc_skf, model.uop, model())
4653
nmpc_skf.estim()
@@ -67,7 +74,7 @@ initstate!(nmpc_im, nlmodel.uop, y)
6774
u = nmpc_im([55, 30], ym=y)
6875
sim!(nmpc_im, 3, [55, 30])
6976

70-
nmpc_ukf = setconstraint!(NonLinMPC(UnscentedKalmanFilter(nlmodel), Hp=10, Cwt=1e3), ymin=[45, -Inf])
77+
nmpc_ukf = setconstraint!(NonLinMPC(UnscentedKalmanFilter(nlmodel), Hp=10, Cwt=10), ymin=[45, -Inf])
7178
initstate!(nmpc_ukf, nlmodel.uop, y)
7279
u = nmpc_ukf([55, 30])
7380
sim!(nmpc_ukf, 3, [55, 30])
@@ -77,6 +84,12 @@ initstate!(nmpc_ekf, model.uop, model())
7784
u = nmpc_ekf([55, 30])
7885
sim!(nmpc_ekf, 3, [55, 30])
7986

87+
nmpc_mhe = setconstraint!(NonLinMPC(MovingHorizonEstimator(nlmodel, He=2), Hp=10, Cwt=Inf), ymin=[45, -Inf])
88+
setconstraint!(nmpc_mhe.estim, x̂min=[-50,-50,-50,-50], x̂max=[50,50,50,50])
89+
initstate!(nmpc_mhe, nlmodel.uop, y)
90+
u = nmpc_mhe([55, 30])
91+
sim!(nmpc_mhe, 3, [55, 30])
92+
8093
function JE( _ , ŶE, _ )
8194
= ŶE[3:end]
8295
Eŷ = repeat([55; 30], 10) -

0 commit comments

Comments
 (0)