Skip to content

Commit 84910fc

Browse files
committed
debug: update current estimated output ŷ for MPC
1 parent 9245324 commit 84910fc

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

src/controller/explicitmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct ExplicitMPC{SE<:StateEstimator} <: PredictiveController
3333
function ExplicitMPC{SE}(estim::SE, Hp, Hc, Mwt, Nwt, Lwt) where {SE<:StateEstimator}
3434
model = estim.model
3535
nu, ny, nd = model.nu, model.ny, model.nd
36-
= zeros(ny)
36+
= copy(model.yop) # dummy vals (updated just before optimization)
3737
Cwt = Inf # no slack variable ϵ for ExplicitMPC
3838
Ewt = 0 # economic costs not supported for ExplicitMPC
3939
validate_weights(model, Hp, Hc, Mwt, Nwt, Lwt, Cwt)

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct LinMPC{SE<:StateEstimator} <: PredictiveController
3636
function LinMPC{SE}(estim::SE, Hp, Hc, Mwt, Nwt, Lwt, Cwt, optim) where {SE<:StateEstimator}
3737
model = estim.model
3838
nu, ny, nd = model.nu, model.ny, model.nd
39-
= zeros(ny)
39+
= copy(model.yop) # dummy vals (updated just before optimization)
4040
Ewt = 0 # economic costs not supported for LinMPC
4141
validate_weights(model, Hp, Hc, Mwt, Nwt, Lwt, Cwt)
4242
M_Hp = Diagonal{Float64}(repeat(Mwt, Hp))

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct NonLinMPC{SE<:StateEstimator, JEfunc<:Function} <: PredictiveController
4141
) where {SE<:StateEstimator, JEFunc<:Function}
4242
model = estim.model
4343
nu, ny, nd = model.nu, model.ny, model.nd
44-
= zeros(ny)
44+
= copy(model.yop) # dummy vals (updated just before optimization)
4545
validate_weights(model, Hp, Hc, Mwt, Nwt, Lwt, Cwt, Ewt)
4646
M_Hp = Diagonal(convert(Vector{Float64}, repeat(Mwt, Hp)))
4747
N_Hc = Diagonal(convert(Vector{Float64}, repeat(Nwt, Hc)))

src/predictive_control.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ Init linear model prediction matrices `F`, `q̃` and `p`.
557557
See [`init_predmat`](@ref) and [`init_quadprog`](@ref) for the definition of the matrices.
558558
"""
559559
function initpred!(mpc::PredictiveController, model::LinModel, d, ym, D̂, R̂y, R̂u)
560+
mpc.ŷ[:] = evalŷ(mpc.estim, ym, d)
560561
predictstoch!(mpc, mpc.estim, d, ym) # init mpc.Ŷop for InternalModel
561562
mpc.F[:] = mpc.K * mpc.estim.+ mpc.V * mpc.estim.lastu0 + mpc.Ŷop
562563
if model.nd 0
@@ -587,6 +588,7 @@ Init `Ŷop`, `d0` and `D̂0` matrices when model is not a [`LinModel`](@ref).
587588
[`InternalModel`](@ref).
588589
"""
589590
function initpred!(mpc::PredictiveController, model::SimModel, d, ym, D̂, R̂y, R̂u)
591+
mpc.ŷ[:] = evalŷ(mpc.estim, ym, d)
590592
predictstoch!(mpc, mpc.estim, d, ym) # init mpc.Ŷop for InternalModel
591593
if model.nd 0
592594
mpc.d0[:], mpc.D̂0[:] = d - model.dop, D̂ - mpc.Dop

0 commit comments

Comments
 (0)