Skip to content

Commit ffef16d

Browse files
committed
debug: getinfo now works
1 parent f867f87 commit ffef16d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/controller/execute.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,29 @@ julia> round.(getinfo(mpc)[:Ŷ], digits=3)
111111
```
112112
"""
113113
function getinfo(mpc::PredictiveController{NT}) where NT<:Real
114-
model = mpc.estim.model
114+
model = mpc.estim.model
115+
nŶe, nUe = (mpc.Hp+1)*model.ny, (mpc.Hp+1)*model.nu
115116
info = Dict{Symbol, Union{JuMP._SolutionSummary, Vector{NT}, NT}}()
116117
Ŷ0, u0, û0 = similar(mpc.Yop), similar(model.uop), similar(model.uop)
117118
Ŷs = similar(mpc.Yop)
118119
x̂0, x̂0next = similar(mpc.estim.x̂0), similar(mpc.estim.x̂0)
119120
Ȳ, Ū = similar(mpc.Yop), similar(mpc.Uop)
121+
Ŷe, Ue = Vector{NT}(undef, nŶe), Vector{NT}(undef, nUe)
120122
Ŷ0, x̂0end = predict!(Ŷ0, x̂0, x̂0next, u0, û0, mpc, model, mpc.ΔŨ)
121-
U0 = mpc.*mpc.ΔŨ + mpc.T_lastu0
122-
J = obj_nonlinprog!(U0, Ȳ, Ū, mpc, model, Ŷ0, mpc.ΔŨ)
123+
Ŷe, Ue = extended_predictions!(Ŷe, Ue, Ū, mpc, model, Ŷ0, mpc.ΔŨ)
124+
J = obj_nonlinprog!(Ȳ, Ū, mpc, model, Ŷe, Ue, mpc.ΔŨ)
125+
U =
126+
U .= @views Ue[1:end-model.nu]
127+
=
128+
Ŷ .= @views Ŷe[model.ny+1:end]
123129
oldF = copy(mpc.F)
124130
predictstoch!(mpc, mpc.estim)
125131
Ŷs .= mpc.F # predictstoch! init mpc.F with Ŷs value if estim is an InternalModel
126132
mpc.F .= oldF # restore old F value
127133
info[:ΔU] = mpc.ΔŨ[1:mpc.Hc*model.nu]
128134
info[] = mpc.== 1 ? mpc.ΔŨ[end] : NaN
129135
info[:J] = J
130-
info[:U] = U0 + mpc.Uop
136+
info[:U] = U
131137
info[:u] = info[:U][1:model.nu]
132138
info[:d] = mpc.d0 + model.dop
133139
info[:D̂] = mpc.D̂0 + mpc.Dop
@@ -385,14 +391,14 @@ function obj_nonlinprog!(
385391
) where NT<:Real
386392
nu, ny = model.nu, model.ny
387393
# --- output setpoint tracking term ---
388-
Ȳ .= Ŷe[ny+1:end]
394+
Ȳ .= @views Ŷe[ny+1:end]
389395
Ȳ .= mpc.R̂y .-
390396
JR̂y = dot(Ȳ, mpc.M_Hp, Ȳ)
391397
# --- move suppression and slack variable term ---
392398
JΔŨ = dot(ΔŨ, mpc.Ñ_Hc, ΔŨ)
393399
# --- input setpoint tracking term ---
394400
if !mpc.noR̂u
395-
Ū .= Ue[1:end-nu]
401+
Ū .= @views Ue[1:end-nu]
396402
Ū .= mpc.R̂u .-
397403
JR̂u = dot(Ū, mpc.L_Hp, Ū)
398404
else

0 commit comments

Comments
 (0)