Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelPredictiveControl"
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
authors = ["Francis Gagnon"]
version = "1.8.1"
version = "1.8.2"

[deps]
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
Expand Down
4 changes: 4 additions & 0 deletions benchmark/2_bench_state_estim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ mhe_pendulum_ipopt_curr = MovingHorizonEstimator(
)
mhe_pendulum_ipopt_curr = setconstraint!(mhe_pendulum_ipopt_curr; v̂min, v̂max)
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_curr.optim)
JuMP.set_attribute(mhe_pendulum_ipopt_curr.optim, "tol", 1e-7)

optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
direct = false
Expand All @@ -311,6 +312,7 @@ mhe_pendulum_ipopt_pred = MovingHorizonEstimator(
)
mhe_pendulum_ipopt_pred = setconstraint!(mhe_pendulum_ipopt_pred; v̂min, v̂max)
JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_pred.optim)
JuMP.set_attribute(mhe_pendulum_ipopt_pred.optim, "tol", 1e-7)

optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
direct = true
Expand All @@ -319,6 +321,7 @@ mhe_pendulum_madnlp_curr = MovingHorizonEstimator(
)
mhe_pendulum_madnlp_curr = setconstraint!(mhe_pendulum_madnlp_curr; v̂min, v̂max)
JuMP.unset_time_limit_sec(mhe_pendulum_madnlp_curr.optim)
JuMP.set_attribute(mhe_pendulum_madnlp_curr.optim, "tol", 1e-7)

optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false)
direct = false
Expand All @@ -327,6 +330,7 @@ mhe_pendulum_madnlp_pred = MovingHorizonEstimator(
)
mhe_pendulum_madnlp_pred = setconstraint!(mhe_pendulum_madnlp_pred; v̂min, v̂max)
JuMP.unset_time_limit_sec(mhe_pendulum_madnlp_pred.optim)
JuMP.set_attribute(mhe_pendulum_madnlp_pred.optim, "tol", 1e-7)

samples, evals, seconds = 10, 1, 15*60
CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Current form"] =
Expand Down
8 changes: 6 additions & 2 deletions test/2_test_state_estim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ end
nonlinmodel = setop!(nonlinmodel, uop=[10,50], yop=[50,30], dop=[5])

mhe1 = MovingHorizonEstimator(nonlinmodel, He=2)
JuMP.set_attribute(mhe1.optim, "tol", 1e-7)
preparestate!(mhe1, [50, 30], [5])
x̂ = updatestate!(mhe1, [10, 50], [50, 30], [5])
@test x̂ ≈ zeros(6) atol=1e-9
Expand Down Expand Up @@ -944,6 +945,7 @@ end
@test mhe1([5]) ≈ [51, 32] atol=1e-3

mhe1 = MovingHorizonEstimator(nonlinmodel, He=2, nint_u=[1, 1], nint_ym=[0, 0], direct=false)
JuMP.set_attribute(mhe1.optim, "tol", 1e-7)
preparestate!(mhe1, [50, 30], [5])
x̂ = updatestate!(mhe1, [10, 50], [50, 30], [5])
@test x̂ ≈ zeros(6) atol=1e-9
Expand Down Expand Up @@ -1065,7 +1067,8 @@ end
updatestate!(mhe1, [0.0], y)
updatestate!(model, [0.1])
end
@test mhe1() ≈ model() atol = 1e-9
preparestate!(mhe1, model())
@test mhe1() ≈ model() atol = 1e-6
model = NonLinModel(f, h, 10.0, 1, 1, 1, solver=nothing)
mhe2 = MovingHorizonEstimator(model, nint_u=[1], He=3, direct=false)
for i = 1:40
Expand All @@ -1074,7 +1077,8 @@ end
updatestate!(mhe2, [0.0], y)
updatestate!(model, [0.1])
end
@test mhe2() ≈ model() atol = 1e-9
preparestate!(mhe2, model())
@test mhe2() ≈ model() atol = 1e-6
end

@testitem "MovingHorizonEstimator fallbacks for arrival covariance estimation" setup=[SetupMPCtests] begin
Expand Down
5 changes: 4 additions & 1 deletion test/3_test_predictive_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1022,12 +1022,13 @@ end
end

@testitem "NonLinMPC constraint violation" setup=[SetupMPCtests] begin
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP
gc(Ue, Ŷe, _ ,p , ϵ) = [p[1]*(Ue[1:end-1] .- 4.2 .- ϵ); p[2]*(Ŷe[2:end] .- 3.14 .- ϵ)]
Hp=50

linmodel = LinModel(tf([2], [10000, 1]), 3000.0)
nmpc_lin = NonLinMPC(linmodel; Hp, Hc=5, gc, nc=2Hp, p=[0; 0])
JuMP.set_attribute(nmpc_lin.optim, "constr_viol_tol", 1e-3)

setconstraint!(nmpc_lin, x̂min=[-1e6,-Inf], x̂max=[1e6,+Inf])
setconstraint!(nmpc_lin, umin=[-10], umax=[10])
Expand Down Expand Up @@ -1098,6 +1099,7 @@ end
h = (x,_,p) -> p.C*x
nonlinmodel = NonLinModel(f, h, linmodel.Ts, 1, 1, 1, solver=nothing, p=linmodel)
nmpc = NonLinMPC(nonlinmodel; Hp, Hc=5, gc, nc=2Hp, p=[0; 0])
JuMP.set_attribute(nmpc.optim, "constr_viol_tol", 1e-3)

setconstraint!(nmpc, x̂min=[-1e6,-Inf], x̂max=[+1e6,+Inf])
setconstraint!(nmpc, umin=[-1e6], umax=[+1e6])
Expand Down Expand Up @@ -1167,6 +1169,7 @@ end
nmpc_ms = NonLinMPC(
nonlinmodel; Hp, Hc=5, transcription=MultipleShooting(), gc, nc=2Hp, p=[0; 0]
)
JuMP.set_attribute(nmpc_ms.optim, "constr_viol_tol", 1e-3)

setconstraint!(nmpc_ms, x̂min=[-1e6,-Inf], x̂max=[+1e6,+Inf])
setconstraint!(nmpc_ms, ymin=[-100], ymax=[100])
Expand Down