@@ -13,6 +13,7 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
1313 E:: Float64
1414 R̂u:: Vector{Float64}
1515 R̂y:: Vector{Float64}
16+ noR̂u:: Bool
1617 S̃_Hp:: Matrix{Bool}
1718 T_Hp:: Matrix{Bool}
1819 T_Hc:: Matrix{Bool}
@@ -31,19 +32,18 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
3132 D̂:: Vector{Float64}
3233 Ŷop:: Vector{Float64}
3334 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 }
3536 model = estim. model
3637 nu, ny, nd = model. nu, model. ny, model. nd
3738 ŷ = zeros (ny)
3839 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)
4041 M_Hp = Diagonal {Float64} (repeat (Mwt, Hp))
4142 N_Hc = Diagonal {Float64} (repeat (Nwt, Hc))
4243 L_Hp = Diagonal {Float64} (repeat (Lwt, Hp))
4344 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)
4747 S_Hp, T_Hp, S_Hc, T_Hc = init_ΔUtoU (nu, Hp, Hc)
4848 E, F, G, J, K, Q = init_predmat (estim, model, Hp, Hc)
4949 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
5757 estim, optim, con,
5858 ΔŨ, ŷ,
5959 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,
6161 S̃_Hp, T_Hp, T_Hc,
6262 Ẽ, F, G, J, K, Q, P̃, q̃, p,
6363 Ks, Ps,
@@ -89,12 +89,11 @@ in which the weight matrices are repeated ``H_p`` or ``H_c`` times:
8989 \m athbf{L}_{H_p} &= \t ext{diag}\m athbf{(L,L,...,L)}
9090\e nd{aligned}
9191```
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.
9897
9998This method uses the default state estimator, a [`SteadyKalmanFilter`](@ref) with default
10099arguments.
@@ -107,7 +106,6 @@ arguments.
107106- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\m athbf{N}`` weight matrix (vector).
108107- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\m athbf{L}`` weight matrix (vector).
109108- `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).
111109- `optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer)` : quadratic optimizer used in
112110 the predictive controller, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/reference/models/#JuMP.Model)
113111 (default to [`OSQP.jl`](https://osqp.org/docs/parsers/jump.html) optimizer).
@@ -158,12 +156,11 @@ function LinMPC(
158156 Nwt = fill (DEFAULT_NWT, model. nu),
159157 Lwt = fill (DEFAULT_LWT, model. nu),
160158 Cwt = DEFAULT_CWT,
161- ru = model. uop,
162159 optim:: JuMP.Model = JuMP. Model (OSQP. MathOptInterfaceOSQP. Optimizer),
163160 kwargs...
164161)
165162 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)
167164end
168165
169166
@@ -197,7 +194,6 @@ function LinMPC(
197194 Nwt = fill (DEFAULT_NWT, estim. model. nu),
198195 Lwt = fill (DEFAULT_LWT, estim. model. nu),
199196 Cwt = DEFAULT_CWT,
200- ru = estim. model. uop,
201197 optim:: JuMP.Model = JuMP. Model (OSQP. MathOptInterfaceOSQP. Optimizer)
202198) where {S<: StateEstimator }
203199 isa (estim. model, LinModel) || error (" estim.model type must be LinModel" )
@@ -210,7 +206,7 @@ function LinMPC(
210206 @warn (" prediction horizon Hp ($Hp ) ≤ number of delays in model " *
211207 " ($nk ), the closed-loop system may be zero-gain (unresponsive) or unstable" )
212208 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)
214210end
215211
216212"""
0 commit comments