@@ -2,16 +2,17 @@ const DEFAULT_NONLINMPC_OPTIMIZER = optimizer_with_attributes(Ipopt.Optimizer,"s
22
33struct NonLinMPC{
44 NT<: Real ,
5- SE<: StateEstimator ,
5+ SE<: StateEstimator ,
66 JM<: JuMP.GenericModel ,
77 JEfunc<: Function ,
8+ GCfunc<: Function ,
89 P<: Any
910} <: PredictiveController{NT}
1011 estim:: SE
1112 # note: `NT` and the number type `JNT` in `JuMP.GenericModel{JNT}` can be
1213 # different since solvers that support non-Float64 are scarce.
1314 optim:: JM
14- con:: ControllerConstraint{NT}
15+ con:: ControllerConstraint{NT, GCfunc }
1516 ΔŨ:: Vector{NT}
1617 ŷ :: Vector{NT}
1718 Hp:: Int
@@ -48,9 +49,17 @@ struct NonLinMPC{
4849 Yop:: Vector{NT}
4950 Dop:: Vector{NT}
5051 buffer:: PredictiveControllerBuffer{NT}
51- function NonLinMPC {NT, SE, JM, JEfunc, P} (
52- estim:: SE , Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc, nc, p:: P , optim:: JM
53- ) where {NT<: Real , SE<: StateEstimator , JM<: JuMP.GenericModel , JEfunc<: Function , P<: Any }
52+ function NonLinMPC {NT, SE, JM, JEfunc, GCfunc, P} (
53+ estim:: SE ,
54+ Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc:: GCfunc , nc, p:: P , optim:: JM
55+ ) where {
56+ NT<: Real ,
57+ SE<: StateEstimator ,
58+ JM<: JuMP.GenericModel ,
59+ JEfunc<: Function ,
60+ GCfunc<: Function ,
61+ P<: Any
62+ }
5463 model = estim. model
5564 nu, ny, nd, nx̂ = model. nu, model. ny, model. nd, estim. nx̂
5665 ŷ = copy (model. yop) # dummy vals (updated just before optimization)
@@ -82,7 +91,7 @@ struct NonLinMPC{
8291 nΔŨ = size (Ẽ, 2 )
8392 ΔŨ = zeros (NT, nΔŨ)
8493 buffer = PredictiveControllerBuffer {NT} (nu, ny, nd, Hp)
85- mpc = new {NT, SE, JM, JEfunc, P} (
94+ mpc = new {NT, SE, JM, JEfunc, GCfunc, P} (
8695 estim, optim, con,
8796 ΔŨ, ŷ,
8897 Hp, Hc, nϵ,
@@ -318,9 +327,9 @@ function NonLinMPC(
318327 L_Hp = diagm (repeat (Lwt, Hp)),
319328 Cwt = DEFAULT_CWT,
320329 Ewt = DEFAULT_EWT,
321- JE :: JEfunc = (_,_,_,_) -> 0.0 ,
330+ JE :: JEfunc = (_,_,_,_) -> 0.0 ,
322331 gc!:: Function = (_,_,_,_,_,_) -> nothing ,
323- gc :: Function = gc!,
332+ gc :: GCfunc = gc!,
324333 nc = 0 ,
325334 p:: P = estim. model. p,
326335 optim:: JM = JuMP. Model (DEFAULT_NONLINMPC_OPTIMIZER, add_bridges= false ),
@@ -329,14 +338,15 @@ function NonLinMPC(
329338 SE<: StateEstimator{NT} ,
330339 JM<: JuMP.GenericModel ,
331340 JEfunc<: Function ,
341+ GCfunc<: Function ,
332342 P<: Any
333343}
334344 nk = estimate_delays (estim. model)
335345 if Hp ≤ nk
336346 @warn (" prediction horizon Hp ($Hp ) ≤ estimated number of delays in model " *
337347 " ($nk ), the closed-loop system may be unstable or zero-gain (unresponsive)" )
338348 end
339- return NonLinMPC {NT, SE, JM, JEfunc, P} (
349+ return NonLinMPC {NT, SE, JM, JEfunc, GCfunc, P} (
340350 estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc, nc, p, optim
341351 )
342352end
@@ -520,7 +530,7 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
520530 gc = get_tmp (gc_cache, ΔŨ1)
521531 Ŷ0, x̂0end = predict! (Ȳ, x̂0, x̂0next, u0, û0, mpc, model, ΔŨ)
522532 Ue, Ŷe = extended_predictions! (Ue, Ŷe, Ū, mpc, model, Ŷ0, ΔŨ)
523- ϵ = (nϵ ≠ 0 ) ? ΔŨ[end ] : zero (T) # ϵ = 0 if nϵ == 0 (meaning no relaxation)
533+ ϵ = (nϵ ≠ 0 ) ? ΔŨ[end ] : 0 # ϵ = 0 if nϵ == 0 (meaning no relaxation)
524534 mpc. con. gc! (gc, Ue, Ŷe, mpc. D̂e, mpc. p, ϵ)
525535 g = con_nonlinprog! (g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
526536 return obj_nonlinprog! (Ȳ, Ū, mpc, model, Ue, Ŷe, ΔŨ):: T
@@ -539,7 +549,7 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
539549 gc = get_tmp (gc_cache, ΔŨ1)
540550 Ŷ0, x̂0end = predict! (Ȳ, x̂0, x̂0next, u0, û0, mpc, model, ΔŨ)
541551 Ue, Ŷe = extended_predictions! (Ue, Ŷe, Ū, mpc, model, Ŷ0, ΔŨ)
542- ϵ = (nϵ ≠ 0 ) ? ΔŨ[end ] : zero (T) # ϵ = 0 if nϵ == 0 (meaning no relaxation)
552+ ϵ = (nϵ ≠ 0 ) ? ΔŨ[end ] : 0 # ϵ = 0 if nϵ == 0 (meaning no relaxation)
543553 mpc. con. gc! (gc, Ue, Ŷe, mpc. D̂e, mpc. p, ϵ)
544554 g = con_nonlinprog! (g, mpc, model, x̂0end, Ŷ0, gc, ϵ)
545555 end
0 commit comments