Skip to content

Commit 21f69e1

Browse files
committed
code cleaning for nonlinear constraints
1 parent 1c6107f commit 21f69e1

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/controller/nonlinmpc.jl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,12 @@ function setnonlincon!(mpc::NonLinMPC, ::NonLinModel)
349349
return nothing
350350
end
351351

352-
353-
"""
354-
con_nonlinprog!(C, mpc::NonLinMPC, model::LinModel, ΔŨ::Vector{Real})
355-
356-
Nonlinear constraints for [`NonLinMPC`](@ref) when `model` is a [`LinModel`](@ref).
357-
"""
358-
function con_nonlinprog!(C, ::NonLinMPC, ::LinModel, _ , ::Vector{T}) where {T<:Real}
359-
return C
360-
end
361352
"""
362-
con_nonlinprog!(C, mpc::NonLinMPC, model::NonLinModel, ΔŨ::Vector{Real})
353+
con_nonlinprog!(C, mpc::NonLinMPC, model::SimModel, ΔŨ)
363354
364355
Nonlinear constrains for [`NonLinMPC`](@ref) when `model` is not a [`LinModel`](@ref).
365356
"""
366-
function con_nonlinprog!(C, mpc::NonLinMPC, model::SimModel, Ŷ, ΔŨ::Vector{T}) where {T<:Real}
357+
function con_nonlinprog!(C, mpc::NonLinMPC, model::SimModel, Ŷ, ΔŨ)
367358
ny, Hp = model.ny, mpc.Hp
368359
if !isinf(mpc.C) # constraint softening activated :
369360
ϵ = ΔŨ[end]
@@ -375,4 +366,7 @@ function con_nonlinprog!(C, mpc::NonLinMPC, model::SimModel, Ŷ, ΔŨ::Vector{
375366
end
376367
C[isinf.(C)] .= 0 # replace ±Inf with 0 to avoid INVALID_MODEL error
377368
return C
378-
end
369+
end
370+
371+
"No nonlinear constraints if `model` is a [`LinModel`](@ref), return `C` unchanged."
372+
con_nonlinprog!(C, ::NonLinMPC, ::LinModel, _ , _ ) = C

src/predictive_control.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,9 @@ The function is called by the nonlinear optimizer of [`NonLinMPC`](@ref) control
744744
also be called on any [`PredictiveController`](@ref)s to evaluate the objective function `J`
745745
at specific input increments `ΔŨ` and predictions `Ŷ` values.
746746
"""
747-
function obj_nonlinprog(mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ::Vector{T}) where {T<:Real}
747+
function obj_nonlinprog(
748+
mpc::PredictiveController, model::LinModel, Ŷ, ΔŨ::Vector{T}
749+
) where {T<:Real}
748750
J = obj_quadprog(ΔŨ, mpc.P̃, mpc.q̃)
749751
if !iszero(mpc.E)
750752
U = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*(mpc.estim.lastu0 + model.uop)
@@ -761,7 +763,9 @@ end
761763
762764
Nonlinear programming objective function when `model` is not a [`LinModel`](@ref).
763765
"""
764-
function obj_nonlinprog(mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ::Vector{T}) where {T<:Real}
766+
function obj_nonlinprog(
767+
mpc::PredictiveController, model::SimModel, Ŷ, ΔŨ::Vector{T}
768+
) where {T<:Real}
765769
# --- output setpoint tracking term ---
766770
êy = mpc.R̂y -
767771
JR̂y = êy'*mpc.M_Hp*êy

0 commit comments

Comments
 (0)