Skip to content

Commit e6e3944

Browse files
committed
added: error logging when no solution available
1 parent de99e63 commit e6e3944

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ DAQP = "c47d62df-3981-49c8-9651-128b1cd08617"
44
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
55
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
78
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
89

910
[compat]
1011
ControlSystemsBase = "1"
1112
Documenter = "1"
13+
LinearAlgebra = "1.6"
14+
Logging = "1.6"

docs/src/manual/nonlinmpc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ We test `mpc` performance on `plant` by imposing an angular setpoint of 180° (i
114114
position):
115115

116116
```@example 1
117+
using Logging; disable_logging(Warn) # hide
117118
res_ry = sim!(nmpc, N, [180.0], plant=plant, x0=[0, 0], x̂0=[0, 0, 0])
118119
plot(res_ry)
119120
savefig(ans, "plot3_NonLinMPC.svg"); nothing # hide

src/predictive_control.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,18 @@ function optim_objective!(mpc::PredictiveController)
726726
end
727727
end
728728
status = termination_status(optim)
729+
ΔŨcurr, ΔŨlast = value.(ΔŨvar), ΔŨ0
729730
if !(status == OPTIMAL || status == LOCALLY_SOLVED)
730-
@warn "MPC termination status not OPTIMAL or LOCALLY_SOLVED ($status)"
731+
if isfatal(status)
732+
@error("MPC terminated without solution: returning last solution shifted",
733+
status, ΔŨcurr, ΔŨlast)
734+
else
735+
@warn("MPC termination status not OPTIMAL or LOCALLY_SOLVED: keeping "*
736+
"solution anyway", status, ΔŨcurr, ΔŨlast)
737+
end
731738
@debug solution_summary(optim, verbose=true)
732739
end
733-
mpc.ΔŨ[:] = isfatal(status) ? ΔŨ0 : value.(ΔŨvar) # fatal status : use last value
740+
mpc.ΔŨ[:] = isfatal(status) ? ΔŨlast : ΔŨcurr
734741
return mpc.ΔŨ
735742
end
736743

0 commit comments

Comments
 (0)