@@ -52,25 +52,17 @@ for details on bounds and softness parameters ``\mathbf{c}``. The output and ter
52
52
constraints are all soft by default. See Extended Help for time-varying constraints.
53
53
54
54
# Arguments
55
- - `mpc::PredictiveController` : predictive controller to set constraints.
56
- - `umin = fill(-Inf,nu)` : manipulated input lower bounds ``\m athbf{u_{min}}``.
57
- - `umax = fill(+Inf,nu)` : manipulated input upper bounds ``\m athbf{u_{max}}``.
58
- - `Δumin = fill(-Inf,nu)` : manipulated input increment lower bounds ``\m athbf{Δu_{min}}``.
59
- - `Δumax = fill(+Inf,nu)` : manipulated input increment upper bounds ``\m athbf{Δu_{max}}``.
60
- - `ymin = fill(-Inf,ny)` : predicted output lower bounds ``\m athbf{y_{min}}``.
61
- - `ymax = fill(+Inf,ny)` : predicted output upper bounds ``\m athbf{y_{max}}``.
62
- - `x̂min = fill(-Inf,nx̂)` : terminal constraint lower bounds ``\m athbf{x̂_{min}}``.
63
- - `x̂max = fill(+Inf,nx̂)` : terminal constraint upper bounds ``\m athbf{x̂_{max}}``.
64
- - `c_umin = fill(0.0,nu)` : `umin` softness weights ``\m athbf{c_{u_{min}}}``.
65
- - `c_umax = fill(0.0,nu)` : `umax` softness weights ``\m athbf{c_{u_{max}}}``.
66
- - `c_Δumin = fill(0.0,nu)` : `Δumin` softness weights ``\m athbf{c_{Δu_{min}}}``.
67
- - `c_Δumax = fill(0.0,nu)` : `Δumax` softness weights ``\m athbf{c_{Δu_{max}}}``.
68
- - `c_ymin = fill(1.0,ny)` : `ymin` softness weights ``\m athbf{c_{y_{min}}}``.
69
- - `c_ymax = fill(1.0,ny)` : `ymax` softness weights ``\m athbf{c_{y_{max}}}``.
70
- - `c_x̂min = fill(1.0,nx̂)` : `x̂min` softness weights ``\m athbf{c_{x̂_{min}}}``.
71
- - `c_x̂max = fill(1.0,nx̂)` : `x̂max` softness weights ``\m athbf{c_{x̂_{max}}}``.
55
+ - `mpc::PredictiveController` : predictive controller to set constraints
56
+ - `umin=fill(-Inf,nu)` / `umax=fill(+Inf,nu)` : manipulated input bound ``\m athbf{u_{min/max}}``
57
+ - `Δumin=fill(-Inf,nu)` / `Δumax=fill(+Inf,nu)` : manipulated input increment bound ``\m athbf{Δu_{min/max}}``
58
+ - `ymin=fill(-Inf,ny)` / `ymax=fill(+Inf,ny)` : predicted output bound ``\m athbf{y_{min/max}}``
59
+ - `x̂min=fill(-Inf,nx̂)` / `x̂max=fill(+Inf,nx̂)` : terminal constraint bound ``\m athbf{x̂_{min/max}}``
60
+ - `c_umin=fill(0.0,nu)` / `c_umax=fill(0.0,nu)` : `umin` / `umax` softness weight ``\m athbf{c_{u_{min/max}}}``
61
+ - `c_Δumin=fill(0.0,nu)` / `c_Δumax=fill(0.0,nu)` : `Δumin` / `Δumax` softness weight ``\m athbf{c_{Δu_{min/max}}}``
62
+ - `c_ymin=fill(1.0,ny)` / `c_ymax=fill(1.0,ny)` : `ymin` / `ymax` softness weight ``\m athbf{c_{y_{min/max}}}``
63
+ - `c_x̂min=fill(1.0,nx̂)` / `c_x̂max=fill(1.0,nx̂)` : `x̂min` / `x̂max` softness weight ``\m athbf{c_{x̂_{min/max}}}``
72
64
- all the keyword arguments above but with a first capital letter, except for the terminal
73
- constraints, e.g. `Ymax` or `C_Δumin`: for time-varying constraints (see Extended Help).
65
+ constraints, e.g. `Ymax` or `C_Δumin`: for time-varying constraints (see Extended Help)
74
66
75
67
# Examples
76
68
```jldoctest
@@ -134,31 +126,7 @@ function setconstraint!(
134
126
C_umax = nothing , C_umin = nothing ,
135
127
C_Δumax = nothing , C_Δumin = nothing ,
136
128
C_ymax = nothing , C_ymin = nothing ,
137
- # TODO :
138
- # ------------ will be deleted in the future ---------------
139
- ŷmin = nothing , ŷmax = nothing ,
140
- c_ŷmin = nothing , c_ŷmax = nothing ,
141
- # ----------------------------------------------------------
142
129
)
143
- # TODO :
144
- # ----- these 4 `if`s will be deleted in the future --------
145
- if ! isnothing (ŷmin)
146
- Base. depwarn (" keyword arg ŷmin is deprecated, use ymin instead" , :setconstraint! )
147
- ymin = ŷmin
148
- end
149
- if ! isnothing (ŷmax)
150
- Base. depwarn (" keyword arg ŷmax is deprecated, use ymax instead" , :setconstraint! )
151
- ymax = ŷmax
152
- end
153
- if ! isnothing (c_ŷmin)
154
- Base. depwarn (" keyword arg ŷmin is deprecated, use ymin instead" , :setconstraint! )
155
- c_ymin = c_ŷmin
156
- end
157
- if ! isnothing (c_ŷmax)
158
- Base. depwarn (" keyword arg ŷmax is deprecated, use ymax instead" , :setconstraint! )
159
- c_ymax = c_ŷmax
160
- end
161
- # ----------------------------------------------------------
162
130
model, con, optim = mpc. estim. model, mpc. con, mpc. optim
163
131
nu, ny, nx̂, Hp, Hc = model. nu, model. ny, mpc. estim. nx̂, mpc. Hp, mpc. Hc
164
132
notSolvedYet = (termination_status (optim) == OPTIMIZE_NOT_CALLED)
@@ -339,11 +307,22 @@ end
339
307
setnonlincon! (:: PredictiveController , :: SimModel ) = nothing
340
308
341
309
"""
342
- default_Hp(model::LinModel, Hp)
310
+ default_Hp(model::LinModel)
311
+
312
+ Estimate the default prediction horizon `Hp` for [`LinModel`](@ref).
313
+ """
314
+ default_Hp (model:: LinModel ) = DEFAULT_HP0 + estimate_delays (model)
315
+ " Throw an error when model is not a [`LinModel`](@ref)."
316
+ function default_Hp (:: SimModel )
317
+ throw (ArgumentError (" Prediction horizon Hp must be explicitly specified if model is not a LinModel." ))
318
+ end
319
+
320
+ """
321
+ estimate_delays(model::LinModel)
343
322
344
- Estimate the default prediction horizon `Hp ` with a security margin for [`LinModel`](@ref) .
323
+ Estimate the number of delays in `model ` with a security margin.
345
324
"""
346
- function default_Hp (model:: LinModel , Hp )
325
+ function estimate_delays (model:: LinModel )
347
326
# TODO : also check for settling time (poles)
348
327
# TODO : also check for non minimum phase systems (zeros)
349
328
# TODO : replace sum with max delay between all the I/O
@@ -352,36 +331,10 @@ function default_Hp(model::LinModel, Hp)
352
331
# atol=1e-3 to overestimate the number of delays : for closed-loop stability, it is
353
332
# better to overestimate the default value of Hp, as a security margin.
354
333
nk = sum (isapprox .(abs .(poles), 0.0 , atol= 1e-3 )) # number of delays
355
- if isnothing (Hp)
356
- Hp = DEFAULT_HP0 + nk
357
- end
358
- if Hp ≤ nk
359
- @warn (" prediction horizon Hp ($Hp ) ≤ estimated number of delays in model " *
360
- " ($nk ), the closed-loop system may be unstable or zero-gain (unresponsive)" )
361
- end
362
- return Hp
363
- end
364
-
365
- """
366
- default_Hp(model::SimModel, Hp)
367
-
368
- Throw an error if `isnothing(Hp)` when model is not a [`LinModel`](@ref).
369
- """
370
- function default_Hp (:: SimModel , Hp)
371
- if isnothing (Hp)
372
- # TODO :
373
- # ------------ will be deleted in the future ------------------------------------
374
- Base. depwarn (" Hp=nothing is deprecated for NonLinModel, explicitly specify an " *
375
- " integer value" , :NonLinMPC )
376
- Hp = DEFAULT_HP0
377
- # ------------- and replaced by this -------------------------------------------
378
- # throw(ArgumentError("Prediction horizon Hp must be explicitly specified if "*
379
- # "model is not a LinModel."))
380
- # Hp = 0
381
- # -----------------------------------------------------------------------------
382
- end
383
- return Hp
334
+ return nk
384
335
end
336
+ " Return `0` when model is not a [`LinModel`](@ref)."
337
+ estimate_delays (:: SimModel ) = 0
385
338
386
339
"""
387
340
validate_args(mpc::PredictiveController, ry, d, D̂, R̂y, R̂u)
0 commit comments