Skip to content

Commit fc4f647

Browse files
committed
multiple dispatch for ŷ calculation
1 parent 097d430 commit fc4f647

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

example/juMPC.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ setconstraint!(mpc, ŷmin=[-Inf,-Inf], ŷmax=[55, 35])
9595
setconstraint!(mpc, Δumin=[-Inf,-Inf],Δumax=[+Inf,+Inf])
9696

9797
function test_mpc(model, mpc)
98-
N = 200
98+
N = 2000
9999
u_data = zeros(2,N)
100100
y_data = zeros(2,N)
101101
r_data = zeros(2,N)
@@ -130,7 +130,7 @@ function test_mpc(model, mpc)
130130
end
131131

132132
@time u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
133-
#profview u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
133+
@profview u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
134134
#=
135135
using PlotThemes, Plots
136136
#theme(:default)

src/predictive_control.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,14 @@ function write_info!(mpc::LinMPC, ΔŨ, J, ŷs, Ŷs, lastu, F, ym, d)
845845
mpc.info.J = J
846846
mpc.info.U = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*lastu
847847
mpc.info.u = mpc.info.U[1:mpc.estim.model.nu]
848-
mpc.info.= isa(mpc.estim, InternalModel) ? mpc.estim(ym, d) : mpc.estim(d)
848+
mpc.info.= eval_ŷ(mpc.estim, ym, d)
849849
mpc.info.= mpc.*ΔŨ + F
850850
mpc.info.ŷs, mpc.info.Ŷs = ŷs, Ŷs
851851
end
852+
"Evaluate current output of `InternalModel` estimator."
853+
eval_ŷ(estim::InternalModel, ym, d) = estim(ym, d)
854+
"Evaluate current output of the other `StateEstimator`s."
855+
eval_ŷ(estim::StateEstimator, _, d) = estim(d)
852856

853857
"Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
854858
function repeat_constraints(Hp, Hc, umin, umax, Δumin, Δumax, ŷmin, ŷmax)

0 commit comments

Comments
 (0)