Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed: error handling one less alloc #47

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/controller/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
rethrow(err)
end
end
ΔŨcurr, ΔŨlast = value.(ΔŨvar), ΔŨ0
if !issolved(optim)
status = termination_status(optim)
if iserror(optim)
Expand All @@ -457,7 +456,11 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
end
@debug solution_summary(optim, verbose=true)
end
mpc.ΔŨ .= iserror(optim) ? ΔŨlast : ΔŨcurr
if iserror(optim)
mpc.ΔŨ .= ΔŨ0
else
mpc.ΔŨ .= value.(ΔŨvar)
end
return mpc.ΔŨ
end

Expand Down
7 changes: 5 additions & 2 deletions src/estimator/mhe/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function update_estimate!(estim::MovingHorizonEstimator{NT}, u, ym, d) where NT<
end
end
# -------- error handling -------------------------
Z̃curr, Z̃last = value.(Z̃var), Z̃0
if !issolved(optim)
status = termination_status(optim)
if iserror(optim)
Expand All @@ -74,7 +73,11 @@ function update_estimate!(estim::MovingHorizonEstimator{NT}, u, ym, d) where NT<
end
@debug solution_summary(optim, verbose=true)
end
estim.Z̃ .= iserror(optim) ? Z̃last : Z̃curr
if iserror(optim)
mpc.Z̃ .= Z̃0
else
mpc.Z̃ .= value.(Z̃var)
end
# --------- update estimate -----------------------
estim.Ŵ[1:nŵ*Nk] .= @views estim.Z̃[nx̃+1:nx̃+nŵ*Nk] # update Ŵ with optimum for warm-start
V̂, X̂ = predict!(V̂, X̂, û, ŷ, estim, model, estim.Z̃)
Expand Down
Loading