Skip to content

Commit 754ff5c

Browse files
committed
added: distinct verify_delays function
Making it a separate allow creating in a exception for Mooncake, with the `@mooncake_overlay` mechanism.
1 parent a20a1c9 commit 754ff5c

4 files changed

Lines changed: 16 additions & 21 deletions

File tree

‎src/controller/construct.jl‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,24 @@ reset_nonlincon!(::PredictiveController) = nothing
573573
Estimate the default prediction horizon `Hp` for [`LinModel`](@ref).
574574
"""
575575
default_Hp(model::LinModel) = DEFAULT_HP0 + estimate_delays(model)
576-
"Throw an error when model is not a [`LinModel`](@ref)."
576+
"Throw an error when `model` is not a [`LinModel`](@ref)."
577577
function default_Hp(::SimModelODE)
578578
msg = "Prediction horizon Hp must be explicitly specified if model is not a LinModel."
579579
throw(ArgumentError(msg))
580580
end
581581

582+
"Warn if `Hp ≤ nk`, where `nk` is the estimated delays `model`."
583+
function verify_delays(model::LinModel, Hp)
584+
nk = estimate_delays(model)
585+
if Hp ≤ nk
586+
@warn("prediction horizon Hp ($Hp) ≤ estimated number of delays in model "*
587+
"($nk), the closed-loop system may be unstable or zero-gain (unresponsive)")
588+
end
589+
return nothing
590+
end
591+
"Do nothing when `model` is not a [`LinModel`](@ref)."
592+
verify_delays(::SimModel, _ ) = nothing
593+
582594
"""
583595
estimate_delays(model::LinModel)
584596

‎src/controller/explicitmpc.jl‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,7 @@ function ExplicitMPC(
170170
warn_cond=1e6,
171171
) where {NT<:Real, SE<:StateEstimator{NT}}
172172
isa(estim.model, LinModel) || error(MSG_LINMODEL_ERR)
173-
nk = try
174-
estimate_delays(estim.model)
175-
catch myerr
176-
NaN
177-
end
178-
if Hp ≤ nk
179-
@warn("prediction horizon Hp ($Hp) ≤ estimated number of delays in model "*
180-
"($nk), the closed-loop system may be unstable or zero-gain (unresponsive)")
181-
end
182-
isnan(nk) && @warn("could not estimate the model delay, Hp ($Hp) might be too small.")
173+
verify_delays(estim.model, Hp)
183174
nb = move_blocking(Hp, Hc)
184175
Hc = get_Hc(nb)
185176
weights = ControllerWeights(estim.model, Hp, Hc, M_Hp, N_Hc, L_Hp)

‎src/controller/linmpc.jl‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ function LinMPC(
309309
warn_cond=1e6
310310
) where {NT<:Real, SE<:StateEstimator{NT}, JM<:JuMP.GenericModel}
311311
isa(estim.model, LinModel) || error(MSG_LINMODEL_ERR)
312-
nk = estimate_delays(estim.model)
313-
if Hp ≤ nk
314-
@warn("prediction horizon Hp ($Hp) ≤ estimated number of delays in model "*
315-
"($nk), the closed-loop system may be unstable or zero-gain (unresponsive)")
316-
end
312+
verify_delays(estim.model, Hp)
317313
nb = move_blocking(Hp, Hc)
318314
Hc = get_Hc(nb)
319315
weights = ControllerWeights(estim.model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt)

‎src/controller/nonlinmpc.jl‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,7 @@ function NonLinMPC(
449449
NT<:Real,
450450
SE<:StateEstimator{NT}
451451
}
452-
nk = estimate_delays(estim.model)
453-
if Hp ≤ nk
454-
@warn("prediction horizon Hp ($Hp) ≤ estimated number of delays in model "*
455-
"($nk), the closed-loop system may be unstable or zero-gain (unresponsive)")
456-
end
452+
verify_delays(estim.model, Hp)
457453
nb = move_blocking(Hp, Hc)
458454
Hc = get_Hc(nb)
459455
validate_JE(NT, JE)

0 commit comments

Comments
 (0)