@@ -34,21 +34,17 @@ struct LinMPC{SE<:StateEstimator} <: PredictiveController
3434 D̂E:: Vector{Float64}
3535 Ŷop:: Vector{Float64}
3636 Dop:: Vector{Float64}
37- function LinMPC {SE} (estim:: SE , Hp, Hc, Mwt, Nwt, Lwt , Cwt, optim) where {SE<: StateEstimator }
37+ function LinMPC {SE} (estim:: SE , Hp, Hc, M_Hp, N_Hc, L_Hp , Cwt, optim) where {SE<: StateEstimator }
3838 model = estim. model
3939 nu, ny, nd = model. nu, model. ny, model. nd
4040 ŷ = copy (model. yop) # dummy vals (updated just before optimization)
4141 Ewt = 0 # economic costs not supported for LinMPC
42- validate_weights (model, Hp, Hc, Mwt, Nwt, Lwt, Cwt)
43- M_Hp = Diagonal {Float64} (repeat (Mwt, Hp))
44- N_Hc = Diagonal {Float64} (repeat (Nwt, Hc))
45- L_Hp = Diagonal {Float64} (repeat (Lwt, Hp))
46- C = Cwt
42+ validate_weights (model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt)
4743 R̂y, R̂u = zeros (ny* Hp), zeros (nu* Hp) # dummy vals (updated just before optimization)
4844 noR̂u = iszero (L_Hp)
4945 S, T = init_ΔUtoU (nu, Hp, Hc)
5046 E, F, G, J, K, V, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂ = init_predmat (estim, model, Hp, Hc)
51- con, S̃, Ñ_Hc, Ẽ = init_defaultcon (estim, Hp, Hc, C , S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂)
47+ con, S̃, Ñ_Hc, Ẽ = init_defaultcon (estim, Hp, Hc, Cwt , S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂)
5248 P̃, q̃, p = init_quadprog (model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
5349 Ks, Ps = init_stochpred (estim, Hp)
5450 # dummy vals (updated just before optimization):
@@ -113,6 +109,8 @@ arguments.
113109- `optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer)` : quadratic optimizer used in
114110 the predictive controller, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)
115111 (default to [`OSQP.jl`](https://osqp.org/docs/parsers/jump.html) optimizer).
112+ - `M_Hp` / `N_Hc` / `L_Hp` : diagonal matrices ``\m athbf{M}_{H_p}, \m athbf{N}_{H_c},
113+ \m athbf{L}_{H_p}``, for time-varying weights (generated by `Mwt`, `Nwt`, `Lwt` if omitted).
116114- additional keyword arguments are passed to [`SteadyKalmanFilter`](@ref) constructor.
117115
118116# Examples
@@ -137,20 +135,20 @@ costs). The default `Lwt` value implies that this feature is disabled by default
137135
138136The objective function follows this nomenclature:
139137
140- | VARIABLE | DESCRIPTION | SIZE |
141- | :--------------- | :------------------------------------------------- | :--------------- |
142- | ``H_p`` | prediction horizon (integer) | `()` |
143- | ``H_c`` | control horizon (integer) | `()` |
144- | ``\m athbf{ΔU}`` | manipulated input increments over ``H_c`` | `(nu*Hc,)` |
145- | ``\m athbf{Ŷ}`` | predicted outputs over ``H_p`` | `(ny*Hp,)` |
146- | ``\m athbf{U}`` | manipulated inputs over ``H_p`` | `(nu*Hp,)` |
147- | ``\m athbf{R̂_y}`` | predicted output setpoints over ``H_p`` | `(ny*Hp,)` |
148- | ``\m athbf{R̂_u}`` | predicted manipulated input setpoints over ``H_p`` | `(nu*Hp,)` |
149- | ``\m athbf{M} `` | output setpoint tracking weights | `(ny*Hp, ny*Hp)` |
150- | ``\m athbf{N} `` | manipulated input increment weights | `(nu*Hc, nu*Hc)` |
151- | ``\m athbf{L} `` | manipulated input setpoint tracking weights | `(nu*Hp, nu*Hp)` |
152- | ``C`` | slack variable weight | `()` |
153- | ``ϵ`` | slack variable for constraint softening | `()` |
138+ | VARIABLE | DESCRIPTION | SIZE |
139+ | :------------------- | :------ ------------------------------------------------- | :--------------- |
140+ | ``H_p`` | prediction horizon (integer) | `()` |
141+ | ``H_c`` | control horizon (integer) | `()` |
142+ | ``\m athbf{ΔU}`` | manipulated input increments over ``H_c`` | `(nu*Hc,)` |
143+ | ``\m athbf{Ŷ}`` | predicted outputs over ``H_p`` | `(ny*Hp,)` |
144+ | ``\m athbf{U}`` | manipulated inputs over ``H_p`` | `(nu*Hp,)` |
145+ | ``\m athbf{R̂_y}`` | predicted output setpoints over ``H_p`` | `(ny*Hp,)` |
146+ | ``\m athbf{R̂_u}`` | predicted manipulated input setpoints over ``H_p`` | `(nu*Hp,)` |
147+ | ``\m athbf{M_{H_p}} `` | output setpoint tracking weights over ``H_p`` | `(ny*Hp, ny*Hp)` |
148+ | ``\m athbf{N_{H_c}} `` | manipulated input increment weights over ``H_c`` | `(nu*Hc, nu*Hc)` |
149+ | ``\m athbf{L_{H_p}} `` | manipulated input setpoint tracking weights over ``H_p`` | `(nu*Hp, nu*Hp)` |
150+ | ``C`` | slack variable weight | `()` |
151+ | ``ϵ`` | slack variable for constraint softening | `()` |
154152"""
155153function LinMPC (
156154 model:: LinModel ;
@@ -160,11 +158,14 @@ function LinMPC(
160158 Nwt = fill (DEFAULT_NWT, model. nu),
161159 Lwt = fill (DEFAULT_LWT, model. nu),
162160 Cwt = DEFAULT_CWT,
161+ M_Hp = nothing ,
162+ N_Hc = nothing ,
163+ L_Hp = nothing ,
163164 optim:: JuMP.Model = JuMP. Model (DEFAULT_LINMPC_OPTIMIZER, add_bridges= false ),
164165 kwargs...
165166)
166167 estim = SteadyKalmanFilter (model; kwargs... )
167- return LinMPC (estim; Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim)
168+ return LinMPC (estim; Hp, Hc, Mwt, Nwt, Lwt, Cwt, M_Hp, N_Hc, L_Hp, optim)
168169end
169170
170171
@@ -198,11 +199,17 @@ function LinMPC(
198199 Nwt = fill (DEFAULT_NWT, estim. model. nu),
199200 Lwt = fill (DEFAULT_LWT, estim. model. nu),
200201 Cwt = DEFAULT_CWT,
202+ M_Hp = nothing ,
203+ N_Hc = nothing ,
204+ L_Hp = nothing ,
201205 optim:: JuMP.Model = JuMP. Model (DEFAULT_LINMPC_OPTIMIZER, add_bridges= false ),
202206) where {SE<: StateEstimator }
203207 isa (estim. model, LinModel) || error (" estim.model type must be LinModel" )
204208 Hp = default_Hp (estim. model, Hp)
205- return LinMPC {SE} (estim, Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim)
209+ isnothing (M_Hp) && (M_Hp = Diagonal (repeat (Mwt, Hp)))
210+ isnothing (N_Hc) && (N_Hc = Diagonal (repeat (Nwt, Hc)))
211+ isnothing (L_Hp) && (L_Hp = Diagonal (repeat (Lwt, Hp)))
212+ return LinMPC {SE} (estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, optim)
206213end
207214
208215"""
0 commit comments