@@ -33,6 +33,7 @@ struct NonLinMPC{
3333 Hp:: Int
3434 Hc:: Int
3535 nϵ:: Int
36+ nb:: Vector{Int}
3637 weights:: CW
3738 JE:: JEfunc
3839 p:: PT
@@ -63,7 +64,7 @@ struct NonLinMPC{
6364 Dop:: Vector{NT}
6465 buffer:: PredictiveControllerBuffer{NT}
6566 function NonLinMPC {NT} (
66- estim:: SE , Hp, Hc, weights:: CW ,
67+ estim:: SE , Hp, Hc, nb, weights:: CW ,
6768 JE:: JEfunc , gc!:: GCfunc , nc, p:: PT ,
6869 transcription:: TM , optim:: JM ,
6970 gradient:: GB , jacobian:: JB
@@ -86,7 +87,7 @@ struct NonLinMPC{
8687 R̂y, R̂u, Tu_lastu0 = zeros (NT, ny* Hp), zeros (NT, nu* Hp), zeros (NT, nu* Hp)
8788 lastu0 = zeros (NT, nu)
8889 PΔu = init_ZtoΔU (estim, transcription, Hp, Hc)
89- Pu, Tu = init_ZtoU (estim, transcription, Hp, Hc)
90+ Pu, Tu = init_ZtoU (estim, transcription, Hp, Hc, nb )
9091 E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat (
9192 model, estim, transcription, Hp, Hc
9293 )
@@ -116,7 +117,7 @@ struct NonLinMPC{
116117 estim, transcription, optim, con,
117118 gradient, jacobian,
118119 Z̃, ŷ,
119- Hp, Hc, nϵ,
120+ Hp, Hc, nϵ, nb,
120121 weights,
121122 JE, p,
122123 R̂u, R̂y,
@@ -188,8 +189,10 @@ This controller allocates memory at each time step for the optimization.
188189
189190# Arguments
190191- `model::SimModel` : model used for controller predictions and state estimations.
191- - `Hp=nothing`: prediction horizon ``H_p``, must be specified for [`NonLinModel`](@ref).
192- - `Hc=2` : control horizon ``H_c``.
192+ - `Hp::Int=10+nk` : prediction horizon ``H_p``, `nk` is the number of delays if `model` is a
193+ [`LinModel`](@ref) (must be specified otherwise).
194+ - `Hc::Union{Int, Vector{Int}}=2` : control horizon ``H_c``, custom move blocking pattern is
195+ specified with a vector of integers (see [`move_blocking`](@ref) for details).
193196- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\m athbf{M}`` weight matrix (vector).
194197- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\m athbf{N}`` weight matrix (vector).
195198- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\m athbf{L}`` weight matrix (vector).
@@ -281,12 +284,12 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
281284function NonLinMPC (
282285 model:: SimModel ;
283286 Hp:: Int = default_Hp (model),
284- Hc:: Int = DEFAULT_HC,
287+ Hc:: IntVectorOrInt = DEFAULT_HC,
285288 Mwt = fill (DEFAULT_MWT, model. ny),
286289 Nwt = fill (DEFAULT_NWT, model. nu),
287290 Lwt = fill (DEFAULT_LWT, model. nu),
288291 M_Hp = Diagonal (repeat (Mwt, Hp)),
289- N_Hc = Diagonal (repeat (Nwt, Hc )),
292+ N_Hc = Diagonal (repeat (Nwt, get_Hc ( move_blocking (Hp, Hc)) )),
290293 L_Hp = Diagonal (repeat (Lwt, Hp)),
291294 Cwt = DEFAULT_CWT,
292295 Ewt = DEFAULT_EWT,
@@ -338,12 +341,12 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
338341function NonLinMPC (
339342 estim:: SE ;
340343 Hp:: Int = default_Hp (estim. model),
341- Hc:: Int = DEFAULT_HC,
344+ Hc:: IntVectorOrInt = DEFAULT_HC,
342345 Mwt = fill (DEFAULT_MWT, estim. model. ny),
343346 Nwt = fill (DEFAULT_NWT, estim. model. nu),
344347 Lwt = fill (DEFAULT_LWT, estim. model. nu),
345348 M_Hp = Diagonal (repeat (Mwt, Hp)),
346- N_Hc = Diagonal (repeat (Nwt, Hc )),
349+ N_Hc = Diagonal (repeat (Nwt, get_Hc ( move_blocking (Hp, Hc)) )),
347350 L_Hp = Diagonal (repeat (Lwt, Hp)),
348351 Cwt = DEFAULT_CWT,
349352 Ewt = DEFAULT_EWT,
@@ -365,11 +368,13 @@ function NonLinMPC(
365368 @warn (" prediction horizon Hp ($Hp ) ≤ estimated number of delays in model " *
366369 " ($nk ), the closed-loop system may be unstable or zero-gain (unresponsive)" )
367370 end
371+ nb = move_blocking (Hp, Hc)
372+ Hc = get_Hc (nb)
368373 validate_JE (NT, JE)
369374 gc! = get_mutating_gc (NT, gc)
370375 weights = ControllerWeights {NT} (estim. model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
371376 return NonLinMPC {NT} (
372- estim, Hp, Hc, weights, JE, gc!, nc, p, transcription, optim, gradient, jacobian
377+ estim, Hp, Hc, nb, weights, JE, gc!, nc, p, transcription, optim, gradient, jacobian
373378 )
374379end
375380
0 commit comments