@@ -48,7 +48,7 @@ struct NonLinMPC{
4848 buffer:: PredictiveControllerBuffer{NT}
4949 function NonLinMPC {NT, SE, JM, JEfunc, GCfunc, P} (
5050 estim:: SE ,
51- Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc:: GCfunc , nc, p:: P , optim:: JM
51+ Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE:: JEfunc , gc! :: GCfunc , nc, p:: P , optim:: JM
5252 ) where {
5353 NT<: Real ,
5454 SE<: StateEstimator ,
@@ -60,8 +60,6 @@ struct NonLinMPC{
6060 model = estim. model
6161 nu, ny, nd, nx̂ = model. nu, model. ny, model. nd, estim. nx̂
6262 ŷ = copy (model. yop) # dummy vals (updated just before optimization)
63- validate_JE (NT, JE)
64- gc! = get_mutating_gc (NT, gc)
6563 weights = ControllerWeights {NT} (model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
6664 # dummy vals (updated just before optimization):
6765 R̂y, R̂u, T_lastu0 = zeros (NT, ny* Hp), zeros (NT, nu* Hp), zeros (NT, nu* Hp)
@@ -243,7 +241,7 @@ function NonLinMPC(
243241 L_Hp = diagm (repeat (Lwt, Hp)),
244242 Cwt = DEFAULT_CWT,
245243 Ewt = DEFAULT_EWT,
246- JE:: Function = (_,_,_,_) -> 0.0 ,
244+ JE :: Function = (_,_,_,_) -> 0.0 ,
247245 gc!:: Function = (_,_,_,_,_,_) -> nothing ,
248246 gc :: Function = gc!,
249247 nc:: Int = 0 ,
@@ -323,7 +321,7 @@ function NonLinMPC(
323321 Ewt = DEFAULT_EWT,
324322 JE :: JEfunc = (_,_,_,_) -> 0.0 ,
325323 gc!:: Function = (_,_,_,_,_,_) -> nothing ,
326- gc :: GCfunc = gc!,
324+ gc :: Function = gc!,
327325 nc = 0 ,
328326 p:: P = estim. model. p,
329327 optim:: JM = JuMP. Model (DEFAULT_NONLINMPC_OPTIMIZER, add_bridges= false ),
@@ -332,16 +330,18 @@ function NonLinMPC(
332330 SE<: StateEstimator{NT} ,
333331 JM<: JuMP.GenericModel ,
334332 JEfunc<: Function ,
335- GCfunc<: Function ,
336333 P<: Any
337334}
338335 nk = estimate_delays (estim. model)
339336 if Hp ≤ nk
340337 @warn (" prediction horizon Hp ($Hp ) ≤ estimated number of delays in model " *
341338 " ($nk ), the closed-loop system may be unstable or zero-gain (unresponsive)" )
342339 end
340+ validate_JE (NT, JE)
341+ gc! = get_mutating_gc (NT, gc)
342+ GCfunc = get_type_mutating_gc (gc!)
343343 return NonLinMPC {NT, SE, JM, JEfunc, GCfunc, P} (
344- estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc, nc, p, optim
344+ estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc! , nc, p, optim
345345 )
346346end
347347
@@ -398,6 +398,9 @@ function get_mutating_gc(NT, gc)
398398 return gc!
399399end
400400
401+ " Get the type of the mutating version of the custom constrain function `gc!`."
402+ get_type_mutating_gc (:: GCfunc ) where {GCfunc<: Function } = GCfunc
403+
401404"""
402405 test_custom_functions(NT, model::SimModel, JE, gc!, nc, Uop, Yop, Dop, p)
403406
0 commit comments