Skip to content

Commit cbe1811

Browse files
committed
changed: error handling one less alloc
1 parent 5ff0fe4 commit cbe1811

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/controller/execute.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
445445
rethrow(err)
446446
end
447447
end
448-
ΔŨcurr, ΔŨlast = value.(ΔŨvar), ΔŨ0
449448
if !issolved(optim)
450449
status = termination_status(optim)
451450
if iserror(optim)
@@ -457,7 +456,11 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
457456
end
458457
@debug solution_summary(optim, verbose=true)
459458
end
460-
mpc.ΔŨ .= iserror(optim) ? ΔŨlast : ΔŨcurr
459+
if iserror(optim)
460+
mpc.ΔŨ .= ΔŨ0
461+
else
462+
mpc.ΔŨ .= value.(ΔŨvar)
463+
end
461464
return mpc.ΔŨ
462465
end
463466

src/estimator/mhe/execute.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function update_estimate!(estim::MovingHorizonEstimator{NT}, u, ym, d) where NT<
6262
end
6363
end
6464
# -------- error handling -------------------------
65-
Z̃curr, Z̃last = value.(Z̃var), Z̃0
6665
if !issolved(optim)
6766
status = termination_status(optim)
6867
if iserror(optim)
@@ -74,7 +73,11 @@ function update_estimate!(estim::MovingHorizonEstimator{NT}, u, ym, d) where NT<
7473
end
7574
@debug solution_summary(optim, verbose=true)
7675
end
77-
estim.Z̃ .= iserror(optim) ? Z̃last : Z̃curr
76+
if iserror(optim)
77+
mpc.Z̃ .= Z̃0
78+
else
79+
mpc.Z̃ .= value.(Z̃var)
80+
end
7881
# --------- update estimate -----------------------
7982
estim.Ŵ[1:nŵ*Nk] .= @views estim.Z̃[nx̃+1:nx̃+nŵ*Nk] # update Ŵ with optimum for warm-start
8083
V̂, X̂ = predict!(V̂, X̂, û, ŷ, estim, model, estim.Z̃)

0 commit comments

Comments
 (0)