Skip to content

Commit cf50ced

Browse files
committed
debug : restore ymin and ymax default value to Inf
1 parent 41a9635 commit cf50ced

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
33
authors = ["Francis Gagnon"]
4-
version = "0.4.0"
4+
version = "0.4.1"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"

src/controller/nonlinmpc.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,16 @@ function con_nonlinprog(mpc::NonLinMPC, model::SimModel, ΔŨ::NTuple{N, T}) wh
279279
ΔŨ = collect(ΔŨ) # convert NTuple to Vector
280280
U0 = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*(mpc.estim.lastu0)
281281
= evalŶ(mpc, model, mpc.x̂d, mpc.d0, mpc.D̂0, U0)
282-
C_Ŷmin = (mpc.con.Ŷmin - Ŷ)
283-
C_Ŷmax = (Ŷ - mpc.con.Ŷmax)
282+
# replace -Inf with 0 to avoid INVALID_MODEL error
283+
C_Ŷmin = zeros(T, length(Ŷ))
284+
C_Ŷmax = zeros(T, length(Ŷ))
284285
if !isinf(mpc.C) # constraint softening activated :
285286
ϵ = ΔŨ[end]
286-
C_Ŷmin = C_Ŷmin - ϵ*mpc.con.c_Ŷmin
287-
C_Ŷmax = C_Ŷmax - ϵ*mpc.con.c_Ŷmin
287+
C_Ŷmin[mpc.con.i_Ŷmin] = (mpc.con.Ŷmin -- ϵ*mpc.con.c_Ŷmin)[mpc.con.i_Ŷmin]
288+
C_Ŷmax[mpc.con.i_Ŷmax] = (Ŷ - mpc.con.Ŷmax - ϵ*mpc.con.c_Ŷmax)[mpc.con.i_Ŷmax]
289+
else # no constraint softening :
290+
C_Ŷmin[mpc.con.i_Ŷmin] = (mpc.con.Ŷmin - Ŷ)[mpc.con.i_Ŷmin]
291+
C_Ŷmax[mpc.con.i_Ŷmax] = (Ŷ - mpc.con.Ŷmax)[mpc.con.i_Ŷmax]
288292
end
289293
C = [C_Ŷmin; C_Ŷmax]
290294
return C

src/predictive_control.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ end
633633
obj_quadprog(ΔŨ, P̃, q̃) = 0.5*ΔŨ'**ΔŨ +'*ΔŨ
634634

635635
"""
636-
initdefaultcon(model, C, S_Hp, S_Hc, N_Hc, E)
636+
init_defaultcon(model, C, S_Hp, S_Hc, N_Hc, E)
637637
638638
Init `ControllerConstraint` struct with default parameters.
639639
@@ -643,7 +643,7 @@ function init_defaultcon(model, Hp, Hc, C, S_Hp, S_Hc, N_Hc, E)
643643
nu, ny = model.nu, model.ny
644644
umin, umax = fill(-Inf, nu), fill(+Inf, nu)
645645
Δumin, Δumax = fill(-Inf, nu), fill(+Inf, nu)
646-
ŷmin, ŷmax = fill(-999, ny), fill(+999, ny)
646+
ŷmin, ŷmax = fill(-Inf, ny), fill(+Inf, ny)
647647
c_umin, c_umax = fill(0.0, nu), fill(0.0, nu)
648648
c_Δumin, c_Δumax = fill(0.0, nu), fill(0.0, nu)
649649
c_ŷmin, c_ŷmax = fill(1.0, ny), fill(1.0, ny)

0 commit comments

Comments
 (0)