@@ -37,6 +37,7 @@ See also [`LinMPC`](@ref), [`ExplicitMPC`](@ref), [`NonLinMPC`](@ref).
3737- `mpc::PredictiveController` : solve optimization problem of `mpc`.
3838- `ry=mpc.estim.model.yop` : current output setpoints ``\m athbf{r_y}(k)``.
3939- `d=[]` : current measured disturbances ``\m athbf{d}(k)``.
40+ - `lastu=mpc.lastu0+mpc.estim.model.uop`: last manipulated input ``\m athbf{u}(k-1)``.
4041- `D̂=repeat(d, mpc.Hp)` or *`Dhat`* : predicted measured disturbances ``\m athbf{D̂}``, constant
4142 in the future by default or ``\m athbf{d̂}(k+j)=\m athbf{d}(k)`` for ``j=1`` to ``H_p``.
4243- `R̂y=repeat(ry, mpc.Hp)` or *`Rhaty`* : predicted output setpoints ``\m athbf{R̂_y}``, constant
@@ -59,6 +60,7 @@ function moveinput!(
5960 mpc:: PredictiveController ,
6061 ry:: Vector = mpc. estim. model. yop,
6162 d :: Vector = mpc. buffer. empty;
63+ lastu:: Vector = (mpc. buffer. u .= mpc. lastu0 .+ mpc. estim. model. uop),
6264 Dhat :: Vector = repeat! (mpc. buffer. D̂, d, mpc. Hp),
6365 Rhaty:: Vector = repeat! (mpc. buffer. Ŷ, ry, mpc. Hp),
6466 Rhatu:: Vector = mpc. Uop,
@@ -69,8 +71,8 @@ function moveinput!(
6971 if mpc. estim. direct && ! mpc. estim. corrected[]
7072 @warn " preparestate! should be called before moveinput! with current estimators"
7173 end
72- validate_args (mpc, ry, d, D̂, R̂y, R̂u)
73- initpred! (mpc, mpc. estim. model, d, D̂, R̂y, R̂u)
74+ validate_args (mpc, ry, d, lastu, D̂, R̂y, R̂u)
75+ initpred! (mpc, mpc. estim. model, d, lastu, D̂, R̂y, R̂u)
7476 linconstraint! (mpc, mpc. estim. model, mpc. transcription)
7577 linconstrainteq! (mpc, mpc. estim. model, mpc. transcription)
7678 Z̃ = optim_objective! (mpc)
@@ -189,7 +191,7 @@ function addinfo!(info, mpc::PredictiveController)
189191end
190192
191193@doc raw """
192- initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂u) -> nothing
194+ initpred!(mpc::PredictiveController, model::LinModel, d, lastu, D̂, R̂y, R̂u) -> nothing
193195
194196Init linear model prediction matrices `F, q̃, r` and current estimated output `ŷ`.
195197
@@ -208,8 +210,8 @@ They are computed with these equations using in-place operations:
208210\e nd{aligned}
209211```
210212"""
211- function initpred! (mpc:: PredictiveController , model:: LinModel , d, D̂, R̂y, R̂u)
212- F = initpred_common! (mpc, model, d, D̂, R̂y, R̂u)
213+ function initpred! (mpc:: PredictiveController , model:: LinModel , d, lastu, D̂, R̂y, R̂u)
214+ F = initpred_common! (mpc, model, d, lastu, D̂, R̂y, R̂u)
213215 F .+ = mpc. B # F = F + B
214216 mul! (F, mpc. K, mpc. estim. x̂0, 1 , 1 ) # F = F + K*x̂0
215217 mul! (F, mpc. V, mpc. lastu0, 1 , 1 ) # F = F + V*lastu0
@@ -241,24 +243,25 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂
241243end
242244
243245@doc raw """
244- initpred!(mpc::PredictiveController, model::SimModel, d, D̂, R̂y, R̂u)
246+ initpred!(mpc::PredictiveController, model::SimModel, d, lastu, D̂, R̂y, R̂u)
245247
246- Init `ŷ, F, d0, D̂0, D̂e, R̂y, R̂u` vectors when model is not a [`LinModel`](@ref).
248+ Init `lastu0, ŷ, F, d0, D̂0, D̂e, R̂y, R̂u` vectors when model is not a [`LinModel`](@ref).
247249"""
248- function initpred! (mpc:: PredictiveController , model:: SimModel , d, D̂, R̂y, R̂u)
249- F = initpred_common! (mpc, model, d, D̂, R̂y, R̂u)
250+ function initpred! (mpc:: PredictiveController , model:: SimModel , d, lastu, D̂, R̂y, R̂u)
251+ F = initpred_common! (mpc, model, d, lastu, D̂, R̂y, R̂u)
250252 return nothing
251253end
252254
253255"""
254- initpred_common!(mpc::PredictiveController, model::SimModel, d, D̂, R̂y, R̂u) -> mpc. F
256+ initpred_common!(mpc::PredictiveController, model::SimModel, d, lastu, D̂, R̂y, R̂u) -> F
255257
256258Common computations of `initpred!` for all types of [`SimModel`](@ref).
257259
258260Will also init `mpc.F` with 0 values, or with the stochastic predictions `Ŷs` if `mpc.estim`
259261is an [`InternalModel`](@ref). The function returns `mpc.F`.
260262"""
261- function initpred_common! (mpc:: PredictiveController , model:: SimModel , d, D̂, R̂y, R̂u)
263+ function initpred_common! (mpc:: PredictiveController , model:: SimModel , d, lastu, D̂, R̂y, R̂u)
264+ mpc. lastu0 .= lastu .- model. uop
262265 mul! (mpc. Tu_lastu0, mpc. Tu, mpc. lastu0)
263266 mpc. ŷ .= evaloutput (mpc. estim, d)
264267 if model. nd > 0
0 commit comments