@@ -13,6 +13,7 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
13
13
E:: Float64
14
14
R̂u:: Vector{Float64}
15
15
R̂y:: Vector{Float64}
16
+ noR̂u:: Bool
16
17
S̃_Hp:: Matrix{Bool}
17
18
T_Hp:: Matrix{Bool}
18
19
T_Hc:: Matrix{Bool}
@@ -31,19 +32,18 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
31
32
D̂:: Vector{Float64}
32
33
Ŷop:: Vector{Float64}
33
34
Dop:: Vector{Float64}
34
- function LinMPC {S} (estim:: S , Hp, Hc, Mwt, Nwt, Lwt, Cwt, ru, optim) where {S<: StateEstimator }
35
+ function LinMPC {S} (estim:: S , Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim) where {S<: StateEstimator }
35
36
model = estim. model
36
37
nu, ny, nd = model. nu, model. ny, model. nd
37
38
ŷ = zeros (ny)
38
39
Ewt = 0 # economic costs not supported for LinMPC
39
- validate_weights (model, Hp, Hc, Mwt, Nwt, Lwt, Cwt, ru )
40
+ validate_weights (model, Hp, Hc, Mwt, Nwt, Lwt, Cwt)
40
41
M_Hp = Diagonal {Float64} (repeat (Mwt, Hp))
41
42
N_Hc = Diagonal {Float64} (repeat (Nwt, Hc))
42
43
L_Hp = Diagonal {Float64} (repeat (Lwt, Hp))
43
44
C = Cwt
44
- # manipulated input setpoint predictions are constant over Hp :
45
- R̂u = ~ iszero (Lwt) ? repeat (ru, Hp) : R̂u = empty (estim. x̂)
46
- R̂y = zeros (ny* Hp) # dummy R̂y (updated just before optimization)
45
+ R̂y, R̂u = zeros (ny* Hp), zeros (nu* Hp) # dummy vals (updated just before optimization)
46
+ noR̂u = iszero (L_Hp)
47
47
S_Hp, T_Hp, S_Hc, T_Hc = init_ΔUtoU (nu, Hp, Hc)
48
48
E, F, G, J, K, Q = init_predmat (estim, model, Hp, Hc)
49
49
con, S̃_Hp, Ñ_Hc, Ẽ = init_defaultcon (model, Hp, Hc, C, S_Hp, S_Hc, N_Hc, E)
@@ -57,7 +57,7 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
57
57
estim, optim, con,
58
58
ΔŨ, ŷ,
59
59
Hp, Hc,
60
- M_Hp, Ñ_Hc, L_Hp, Cwt, Ewt, R̂u, R̂y,
60
+ M_Hp, Ñ_Hc, L_Hp, Cwt, Ewt, R̂u, R̂y, noR̂u,
61
61
S̃_Hp, T_Hp, T_Hc,
62
62
Ẽ, F, G, J, K, Q, P̃, q̃, p,
63
63
Ks, Ps,
@@ -89,12 +89,11 @@ in which the weight matrices are repeated ``H_p`` or ``H_c`` times:
89
89
\m athbf{L}_{H_p} &= \t ext{diag}\m athbf{(L,L,...,L)}
90
90
\e nd{aligned}
91
91
```
92
- The ``\m athbf{ΔU}`` vector includes the manipulated input increments ``\m athbf{Δu}(k+j) =
93
- \m athbf{u}(k+j) - \m athbf{u}(k+j-1)`` from ``j=0`` to ``H_c-1``, the ``\m athbf{Ŷ}`` vector,
94
- the output predictions ``\m athbf{ŷ}(k+j)`` from ``j=1`` to ``H_p``, and the ``\m athbf{U}``
95
- vector, the manipulated inputs ``\m athbf{u}(k+j)`` from ``j=0`` to ``H_p-1``. The
96
- manipulated input setpoint predictions ``\m athbf{R̂_u}`` are constant at ``\m athbf{r_u}``.
97
- See Extended Help for a detailed nomenclature.
92
+ The ``\m athbf{ΔU}`` vector includes the manipulated input increments ``\m athbf{Δu}(k+j) =
93
+ \m athbf{u}(k+j) - \m athbf{u}(k+j-1)`` from ``j=0`` to ``H_c-1``, the ``\m athbf{Ŷ}`` vector,
94
+ the output predictions ``\m athbf{ŷ}(k+j)`` from ``j=1`` to ``H_p``, and the ``\m athbf{U}``
95
+ vector, the manipulated inputs ``\m athbf{u}(k+j)`` from ``j=0`` to ``H_p-1``. See Extended
96
+ Help for a detailed nomenclature.
98
97
99
98
This method uses the default state estimator, a [`SteadyKalmanFilter`](@ref) with default
100
99
arguments.
@@ -107,7 +106,6 @@ arguments.
107
106
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\m athbf{N}`` weight matrix (vector).
108
107
- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\m athbf{L}`` weight matrix (vector).
109
108
- `Cwt=1e5` : slack variable weight ``C`` (scalar), use `Cwt=Inf` for hard constraints only.
110
- - `ru=model.uop` : manipulated input setpoints ``\m athbf{r_u}`` (vector).
111
109
- `optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer)` : quadratic optimizer used in
112
110
the predictive controller, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/reference/models/#JuMP.Model)
113
111
(default to [`OSQP.jl`](https://osqp.org/docs/parsers/jump.html) optimizer).
@@ -158,12 +156,11 @@ function LinMPC(
158
156
Nwt = fill (DEFAULT_NWT, model. nu),
159
157
Lwt = fill (DEFAULT_LWT, model. nu),
160
158
Cwt = DEFAULT_CWT,
161
- ru = model. uop,
162
159
optim:: JuMP.Model = JuMP. Model (OSQP. MathOptInterfaceOSQP. Optimizer),
163
160
kwargs...
164
161
)
165
162
estim = SteadyKalmanFilter (model; kwargs... )
166
- return LinMPC (estim; Hp, Hc, Mwt, Nwt, Lwt, Cwt, ru, optim)
163
+ return LinMPC (estim; Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim)
167
164
end
168
165
169
166
@@ -197,7 +194,6 @@ function LinMPC(
197
194
Nwt = fill (DEFAULT_NWT, estim. model. nu),
198
195
Lwt = fill (DEFAULT_LWT, estim. model. nu),
199
196
Cwt = DEFAULT_CWT,
200
- ru = estim. model. uop,
201
197
optim:: JuMP.Model = JuMP. Model (OSQP. MathOptInterfaceOSQP. Optimizer)
202
198
) where {S<: StateEstimator }
203
199
isa (estim. model, LinModel) || error (" estim.model type must be LinModel" )
@@ -210,7 +206,7 @@ function LinMPC(
210
206
@warn (" prediction horizon Hp ($Hp ) ≤ number of delays in model " *
211
207
" ($nk ), the closed-loop system may be zero-gain (unresponsive) or unstable" )
212
208
end
213
- return LinMPC {S} (estim, Hp, Hc, Mwt, Nwt, Lwt, Cwt, ru, optim)
209
+ return LinMPC {S} (estim, Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim)
214
210
end
215
211
216
212
"""
0 commit comments