11@doc raw """
22 setconstraint!(mpc::PredictiveController; <keyword arguments>) -> mpc
33
4- Set the constraint parameters of `mpc` predictive controller .
4+ Set the constraint parameters of the [`PredictiveController`](@ref) `mpc` .
55
66The predictive controllers support both soft and hard constraints, defined by:
77```math
@@ -13,16 +13,11 @@ The predictive controllers support both soft and hard constraints, defined by:
1313\e nd{alignat*}
1414```
1515and also ``ϵ ≥ 0``. The last line is the terminal constraints applied on the states at the
16- end of the horizon (see Extended Help). All the constraint parameters are vector. Use `±Inf`
17- values when there is no bound. The constraint softness parameters ``\m athbf{c}``, also
18- called equal concern for relaxation, are non-negative values that specify the softness of
19- the associated bound. Use `0.0` values for hard constraints. The output and terminal
16+ end of the horizon (see Extended Help). See [`MovingHorizonEstimator`](@ref) constraints
17+ for details on bounds and softness parameters ``\m athbf{c}``. The output and terminal
2018constraints are all soft by default. See Extended Help for time-varying constraints.
2119
2220# Arguments
23- !!! info
24- Same as above for the keyword arguments and default constraints.
25-
2621- `mpc::PredictiveController` : predictive controller to set constraints.
2722- `umin = fill(-Inf,nu)` : manipulated input lower bounds ``\m athbf{u_{min}}``.
2823- `umax = fill(+Inf,nu)` : manipulated input upper bounds ``\m athbf{u_{max}}``.
@@ -61,34 +56,35 @@ LinMPC controller with a sample time Ts = 4.0 s, OSQP optimizer, SteadyKalmanFil
6156```
6257
6358# Extended Help
64- Terminal constraints provide closed-loop stability guarantees on the nominal plant model.
65- They can render an unfeasible problem however. In practice, a sufficiently large prediction
66- horizon ``H_p`` without terminal constraints is typically enough for stability. Note that
67- terminal constraints are applied on the augmented state vector ``\m athbf{x̂}`` (see
68- [`SteadyKalmanFilter`](@ref) for details on augmentation).
69-
70- For variable constraints, the bounds can be modified after calling [`moveinput!`](@ref),
71- that is, at runtime, but not the softness parameters ``\m athbf{c}``. It is not possible to
72- modify `±Inf` bounds at runtime.
73-
74- !!! tip
75- To keep a variable unconstrained while maintaining the ability to add a constraint later
76- at runtime, set the bound to an absolute value sufficiently large when you create the
77- controller (but different than `±Inf`).
78-
79- It is also possible to specify time-varying constraints over ``H_p`` and ``H_c`` horizons.
80- In such a case, they are defined by:
81- ```math
82- \b egin{alignat*}{3}
83- \m athbf{U_{min} - C_{u_{min}}} ϵ ≤&&\ \m athbf{U} &≤ \m athbf{U_{max} + C_{u_{max}}} ϵ \\
84- \m athbf{ΔU_{min} - C_{Δu_{min}}} ϵ ≤&&\ \m athbf{ΔU} &≤ \m athbf{ΔU_{max} + C_{Δu_{max}}} ϵ \\
85- \m athbf{Y_{min} - C_{y_{min}}} ϵ ≤&&\ \m athbf{Ŷ} &≤ \m athbf{Y_{max} + C_{y_{max}}} ϵ
86- \e nd{alignat*}
87- ```
88- For this, use the same keyword arguments as above but with a capital letter:
89- - `Umin` / `Umax` / `C_umin` / `C_umax` : ``\m athbf{U}`` constraints `(nu*Hp,)`.
90- - `ΔUmin` / `ΔUmax` / `C_Δumin` / `C_Δumax` : ``\m athbf{ΔU}`` constraints `(nu*Hc,)`.
91- - `Ymin` / `Ymax` / `C_ymin` / `C_ymax` : ``\m athbf{Ŷ}`` constraints `(ny*Hp,)`.
59+ !!! details "Extended Help"
60+ Terminal constraints provide closed-loop stability guarantees on the nominal plant model.
61+ They can render an unfeasible problem however. In practice, a sufficiently large
62+ prediction horizon ``H_p`` without terminal constraints is typically enough for
63+ stability. Note that terminal constraints are applied on the augmented state vector
64+ ``\m athbf{x̂}`` (see [`SteadyKalmanFilter`](@ref) for details on augmentation).
65+
66+ For variable constraints, the bounds can be modified after calling [`moveinput!`](@ref),
67+ that is, at runtime, but not the softness parameters ``\m athbf{c}``. It is not possible
68+ to modify `±Inf` bounds at runtime.
69+
70+ !!! tip
71+ To keep a variable unconstrained while maintaining the ability to add a constraint
72+ later at runtime, set the bound to an absolute value sufficiently large when you
73+ create the controller (but different than `±Inf`).
74+
75+ It is also possible to specify time-varying constraints over ``H_p`` and ``H_c``
76+ horizons. In such a case, they are defined by:
77+ ```math
78+ \b egin{alignat*}{3}
79+ \m athbf{U_{min} - C_{u_{min}}} ϵ ≤&&\ \m athbf{U} &≤ \m athbf{U_{max} + C_{u_{max}}} ϵ \\
80+ \m athbf{ΔU_{min} - C_{Δu_{min}}} ϵ ≤&&\ \m athbf{ΔU} &≤ \m athbf{ΔU_{max} + C_{Δu_{max}}} ϵ \\
81+ \m athbf{Y_{min} - C_{y_{min}}} ϵ ≤&&\ \m athbf{Ŷ} &≤ \m athbf{Y_{max} + C_{y_{max}}} ϵ
82+ \e nd{alignat*}
83+ ```
84+ For this, use the same keyword arguments as above but with a capital letter:
85+ - `Umin` / `Umax` / `C_umin` / `C_umax` : ``\m athbf{U}`` constraints `(nu*Hp,)`.
86+ - `ΔUmin` / `ΔUmax` / `C_Δumin` / `C_Δumax` : ``\m athbf{ΔU}`` constraints `(nu*Hc,)`.
87+ - `Ymin` / `Ymax` / `C_ymin` / `C_ymax` : ``\m athbf{Ŷ}`` constraints `(ny*Hp,)`.
9288"""
9389function setconstraint! (
9490 mpc:: PredictiveController ;
@@ -377,49 +373,50 @@ Operating points on ``\mathbf{u}``, ``\mathbf{d}`` and ``\mathbf{y}`` are omitte
377373equations.
378374
379375# Extended Help
380- Using the augmented matrices ``\m athbf{Â, B̂_u, Ĉ, B̂_d, D̂_d}`` in `estim` and the function
381- ``\m athbf{W}(j) = \m athbf{Ĉ} ( ∑_{i=0}^j \m athbf{Â}^i ) \m athbf{B̂_u}``, the prediction
382- matrices are computed by :
383- ```math
384- \b egin{aligned}
385- \m athbf{E} &= \b egin{bmatrix}
386- \m athbf{W}(0) & \m athbf{0} & \c dots & \m athbf{0} \\
387- \m athbf{W}(1) & \m athbf{W}(0) & \c dots & \m athbf{0} \\
388- \v dots & \v dots & \d dots & \v dots \\
389- \m athbf{W}(H_p-1) & \m athbf{W}(H_p-2) & \c dots & \m athbf{W}(H_p-H_c+1) \e nd{bmatrix} \\
390- \m athbf{G} &= \b egin{bmatrix}
391- \m athbf{Ĉ}\m athbf{Â}^{0} \m athbf{B̂_d} \\
392- \m athbf{Ĉ}\m athbf{Â}^{1} \m athbf{B̂_d} \\
393- \v dots \\
394- \m athbf{Ĉ}\m athbf{Â}^{H_p-1} \m athbf{B̂_d} \e nd{bmatrix} \\
395- \m athbf{J} &= \b egin{bmatrix}
396- \m athbf{D̂_d} & \m athbf{0} & \c dots & \m athbf{0} \\
397- \m athbf{Ĉ}\m athbf{Â}^{0} \m athbf{B̂_d} & \m athbf{D̂_d} & \c dots & \m athbf{0} \\
398- \v dots & \v dots & \d dots & \v dots \\
399- \m athbf{Ĉ}\m athbf{Â}^{H_p-2} \m athbf{B̂_d} & \m athbf{Ĉ}\m athbf{Â}^{H_p-3} \m athbf{B̂_d} & \c dots & \m athbf{D̂_d} \e nd{bmatrix} \\
400- \m athbf{K} &= \b egin{bmatrix}
401- \m athbf{Ĉ}\m athbf{Â}^{1} \\
402- \m athbf{Ĉ}\m athbf{Â}^{2} \\
403- \v dots \\
404- \m athbf{Ĉ}\m athbf{Â}^{H_p} \e nd{bmatrix} \\
405- \m athbf{V} &= \b egin{bmatrix}
406- \m athbf{W}(0) \\
407- \m athbf{W}(1) \\
408- \v dots \\
409- \m athbf{W}(H_p-1) \e nd{bmatrix}
410- \e nd{aligned}
411- ```
412- For the terminal constraints, the matrices are computed with the function
413- ``\m athbf{w_x̂}(j) = ( ∑_{i=0}^j \m athbf{Â}^i ) \m athbf{B̂_u}`` and:
414- ```math
415- \b egin{aligned}
416- \m athbf{e_x̂} &= \b egin{bmatrix} \m athbf{w_x̂}(H_p-1) & \m athbf{w_x̂}(H_p-2) & \c dots & \m athbf{w_x̂}(H_p-H_c+1) \e nd{bmatrix} \\
417- \m athbf{g_x̂} &= \m athbf{Â}^{H_p-1} \m athbf{B̂_d} \\
418- \m athbf{j_x̂} &= \b egin{bmatrix} \m athbf{Â}^{H_p-2} \m athbf{B̂_d} & \m athbf{Â}^{H_p-3} \m athbf{B̂_d} & \c dots & \m athbf{0} \e nd{bmatrix} \\
419- \m athbf{k_x̂} &= \m athbf{Â}^{H_p} \\
420- \m athbf{v_x̂} &= \m athbf{w_x̂}(H_p-1)
421- \e nd{aligned}
422- ```
376+ !!! details "Extended Help"
377+ Using the augmented matrices ``\m athbf{Â, B̂_u, Ĉ, B̂_d, D̂_d}`` in `estim` and the
378+ function ``\m athbf{W}(j) = \m athbf{Ĉ} ( ∑_{i=0}^j \m athbf{Â}^i ) \m athbf{B̂_u}``, the
379+ prediction matrices are computed by :
380+ ```math
381+ \b egin{aligned}
382+ \m athbf{E} &= \b egin{bmatrix}
383+ \m athbf{W}(0) & \m athbf{0} & \c dots & \m athbf{0} \\
384+ \m athbf{W}(1) & \m athbf{W}(0) & \c dots & \m athbf{0} \\
385+ \v dots & \v dots & \d dots & \v dots \\
386+ \m athbf{W}(H_p-1) & \m athbf{W}(H_p-2) & \c dots & \m athbf{W}(H_p-H_c+1) \e nd{bmatrix} \\
387+ \m athbf{G} &= \b egin{bmatrix}
388+ \m athbf{Ĉ}\m athbf{Â}^{0} \m athbf{B̂_d} \\
389+ \m athbf{Ĉ}\m athbf{Â}^{1} \m athbf{B̂_d} \\
390+ \v dots \\
391+ \m athbf{Ĉ}\m athbf{Â}^{H_p-1} \m athbf{B̂_d} \e nd{bmatrix} \\
392+ \m athbf{J} &= \b egin{bmatrix}
393+ \m athbf{D̂_d} & \m athbf{0} & \c dots & \m athbf{0} \\
394+ \m athbf{Ĉ}\m athbf{Â}^{0} \m athbf{B̂_d} & \m athbf{D̂_d} & \c dots & \m athbf{0} \\
395+ \v dots & \v dots & \d dots & \v dots \\
396+ \m athbf{Ĉ}\m athbf{Â}^{H_p-2} \m athbf{B̂_d} & \m athbf{Ĉ}\m athbf{Â}^{H_p-3} \m athbf{B̂_d} & \c dots & \m athbf{D̂_d} \e nd{bmatrix} \\
397+ \m athbf{K} &= \b egin{bmatrix}
398+ \m athbf{Ĉ}\m athbf{Â}^{1} \\
399+ \m athbf{Ĉ}\m athbf{Â}^{2} \\
400+ \v dots \\
401+ \m athbf{Ĉ}\m athbf{Â}^{H_p} \e nd{bmatrix} \\
402+ \m athbf{V} &= \b egin{bmatrix}
403+ \m athbf{W}(0) \\
404+ \m athbf{W}(1) \\
405+ \v dots \\
406+ \m athbf{W}(H_p-1) \e nd{bmatrix}
407+ \e nd{aligned}
408+ ```
409+ For the terminal constraints, the matrices are computed with the function
410+ ``\m athbf{w_x̂}(j) = ( ∑_{i=0}^j \m athbf{Â}^i ) \m athbf{B̂_u}`` and:
411+ ```math
412+ \b egin{aligned}
413+ \m athbf{e_x̂} &= \b egin{bmatrix} \m athbf{w_x̂}(H_p-1) & \m athbf{w_x̂}(H_p-2) & \c dots & \m athbf{w_x̂}(H_p-H_c+1) \e nd{bmatrix} \\
414+ \m athbf{g_x̂} &= \m athbf{Â}^{H_p-1} \m athbf{B̂_d} \\
415+ \m athbf{j_x̂} &= \b egin{bmatrix} \m athbf{Â}^{H_p-2} \m athbf{B̂_d} & \m athbf{Â}^{H_p-3} \m athbf{B̂_d} & \c dots & \m athbf{0} \e nd{bmatrix} \\
416+ \m athbf{k_x̂} &= \m athbf{Â}^{H_p} \\
417+ \m athbf{v_x̂} &= \m athbf{w_x̂}(H_p-1)
418+ \e nd{aligned}
419+ ```
423420"""
424421function init_predmat (estim:: StateEstimator{NT} , model:: LinModel , Hp, Hc) where {NT<: Real }
425422 Â, B̂u, Ĉ, B̂d, D̂d = estim. Â, estim. B̂u, estim. Ĉ, estim. B̂d, estim. D̂d
0 commit comments