@@ -33,6 +33,7 @@ struct NonLinMPC{
33
33
Hp:: Int
34
34
Hc:: Int
35
35
nϵ:: Int
36
+ nb:: Vector{Int}
36
37
weights:: CW
37
38
JE:: JEfunc
38
39
p:: PT
@@ -63,7 +64,7 @@ struct NonLinMPC{
63
64
Dop:: Vector{NT}
64
65
buffer:: PredictiveControllerBuffer{NT}
65
66
function NonLinMPC {NT} (
66
- estim:: SE , Hp, Hc, weights:: CW ,
67
+ estim:: SE , Hp, Hc, nb, weights:: CW ,
67
68
JE:: JEfunc , gc!:: GCfunc , nc, p:: PT ,
68
69
transcription:: TM , optim:: JM ,
69
70
gradient:: GB , jacobian:: JB
@@ -86,7 +87,7 @@ struct NonLinMPC{
86
87
R̂y, R̂u, Tu_lastu0 = zeros (NT, ny* Hp), zeros (NT, nu* Hp), zeros (NT, nu* Hp)
87
88
lastu0 = zeros (NT, nu)
88
89
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 )
90
91
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat (
91
92
model, estim, transcription, Hp, Hc
92
93
)
@@ -116,7 +117,7 @@ struct NonLinMPC{
116
117
estim, transcription, optim, con,
117
118
gradient, jacobian,
118
119
Z̃, ŷ,
119
- Hp, Hc, nϵ,
120
+ Hp, Hc, nϵ, nb,
120
121
weights,
121
122
JE, p,
122
123
R̂u, R̂y,
@@ -188,8 +189,10 @@ This controller allocates memory at each time step for the optimization.
188
189
189
190
# Arguments
190
191
- `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).
193
196
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\m athbf{M}`` weight matrix (vector).
194
197
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\m athbf{N}`` weight matrix (vector).
195
198
- `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
281
284
function NonLinMPC (
282
285
model:: SimModel ;
283
286
Hp:: Int = default_Hp (model),
284
- Hc:: Int = DEFAULT_HC,
287
+ Hc:: IntVectorOrInt = DEFAULT_HC,
285
288
Mwt = fill (DEFAULT_MWT, model. ny),
286
289
Nwt = fill (DEFAULT_NWT, model. nu),
287
290
Lwt = fill (DEFAULT_LWT, model. nu),
288
291
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)) )),
290
293
L_Hp = Diagonal (repeat (Lwt, Hp)),
291
294
Cwt = DEFAULT_CWT,
292
295
Ewt = DEFAULT_EWT,
@@ -338,12 +341,12 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
338
341
function NonLinMPC (
339
342
estim:: SE ;
340
343
Hp:: Int = default_Hp (estim. model),
341
- Hc:: Int = DEFAULT_HC,
344
+ Hc:: IntVectorOrInt = DEFAULT_HC,
342
345
Mwt = fill (DEFAULT_MWT, estim. model. ny),
343
346
Nwt = fill (DEFAULT_NWT, estim. model. nu),
344
347
Lwt = fill (DEFAULT_LWT, estim. model. nu),
345
348
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)) )),
347
350
L_Hp = Diagonal (repeat (Lwt, Hp)),
348
351
Cwt = DEFAULT_CWT,
349
352
Ewt = DEFAULT_EWT,
@@ -365,11 +368,13 @@ function NonLinMPC(
365
368
@warn (" prediction horizon Hp ($Hp ) ≤ estimated number of delays in model " *
366
369
" ($nk ), the closed-loop system may be unstable or zero-gain (unresponsive)" )
367
370
end
371
+ nb = move_blocking (Hp, Hc)
372
+ Hc = get_Hc (nb)
368
373
validate_JE (NT, JE)
369
374
gc! = get_mutating_gc (NT, gc)
370
375
weights = ControllerWeights {NT} (estim. model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
371
376
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
373
378
)
374
379
end
375
380
0 commit comments