|
| 1 | + |
1 | 2 | @doc raw""" |
2 | 3 | setconstraint!(mpc::PredictiveController; <keyword arguments>) -> mpc |
3 | 4 |
|
@@ -255,6 +256,56 @@ function setconstraint!( |
255 | 256 | return mpc |
256 | 257 | end |
257 | 258 |
|
| 259 | + |
| 260 | +@doc raw""" |
| 261 | + init_matconstraint_mpc(model::LinModel, |
| 262 | + i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
| 263 | + ) -> i_b, i_g, A |
| 264 | +
|
| 265 | +Init `i_b`, `i_g` and `A` matrices for the linear and nonlinear inequality constraints. |
| 266 | +
|
| 267 | +The linear and nonlinear inequality constraints are respectively defined as: |
| 268 | +```math |
| 269 | +\begin{aligned} |
| 270 | + \mathbf{A ΔŨ } &≤ \mathbf{b} \\ |
| 271 | + \mathbf{g(ΔŨ)} &≤ \mathbf{0} |
| 272 | +\end{aligned} |
| 273 | +``` |
| 274 | +`i_b` is a `BitVector` including the indices of ``\mathbf{b}`` that are finite numbers. |
| 275 | +`i_g` is a similar vector but for the indices of ``\mathbf{g}`` (empty if `model` is a |
| 276 | +[`LinModel`](@ref)). The method also returns the ``\mathbf{A}`` matrix if `args` is |
| 277 | +provided. In such a case, `args` needs to contain all the inequality constraint matrices: |
| 278 | +`A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max`. |
| 279 | +""" |
| 280 | +function init_matconstraint_mpc(::LinModel{NT}, |
| 281 | + i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
| 282 | +) where {NT<:Real} |
| 283 | + i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max] |
| 284 | + i_g = BitVector() |
| 285 | + if isempty(args) |
| 286 | + A = zeros(NT, length(i_b), 0) |
| 287 | + else |
| 288 | + A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max = args |
| 289 | + A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max] |
| 290 | + end |
| 291 | + return i_b, i_g, A |
| 292 | +end |
| 293 | + |
| 294 | +"Init `i_b, A` without outputs and terminal constraints if `model` is not a [`LinModel`](@ref)." |
| 295 | +function init_matconstraint_mpc(::SimModel{NT}, |
| 296 | + i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
| 297 | +) where {NT<:Real} |
| 298 | + i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax] |
| 299 | + i_g = [i_Ymin; i_Ymax; i_x̂min; i_x̂max] |
| 300 | + if isempty(args) |
| 301 | + A = zeros(NT, length(i_b), 0) |
| 302 | + else |
| 303 | + A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, _ , _ , _ , _ = args |
| 304 | + A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax] |
| 305 | + end |
| 306 | + return i_b, i_g, A |
| 307 | +end |
| 308 | + |
258 | 309 | "By default, there is no nonlinear constraint, thus do nothing." |
259 | 310 | setnonlincon!(::PredictiveController, ::SimModel) = nothing |
260 | 311 |
|
@@ -769,56 +820,6 @@ function init_stochpred(estim::StateEstimator{NT}, _ ) where NT<:Real |
769 | 820 | return zeros(NT, 0, estim.nxs), zeros(NT, 0, estim.model.ny) |
770 | 821 | end |
771 | 822 |
|
772 | | - |
773 | | -@doc raw""" |
774 | | - init_matconstraint_mpc(model::LinModel, |
775 | | - i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
776 | | - ) -> i_b, i_g, A |
777 | | -
|
778 | | -Init `i_b`, `i_g` and `A` matrices for the linear and nonlinear inequality constraints. |
779 | | -
|
780 | | -The linear and nonlinear inequality constraints are respectively defined as: |
781 | | -```math |
782 | | -\begin{aligned} |
783 | | - \mathbf{A ΔŨ } &≤ \mathbf{b} \\ |
784 | | - \mathbf{g(ΔŨ)} &≤ \mathbf{0} |
785 | | -\end{aligned} |
786 | | -``` |
787 | | -`i_b` is a `BitVector` including the indices of ``\mathbf{b}`` that are finite numbers. |
788 | | -`i_g` is a similar vector but for the indices of ``\mathbf{g}`` (empty if `model` is a |
789 | | -[`LinModel`](@ref)). The method also returns the ``\mathbf{A}`` matrix if `args` is |
790 | | -provided. In such a case, `args` needs to contain all the inequality constraint matrices: |
791 | | -`A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max`. |
792 | | -""" |
793 | | -function init_matconstraint_mpc(::LinModel{NT}, |
794 | | - i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
795 | | -) where {NT<:Real} |
796 | | - i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max] |
797 | | - i_g = BitVector() |
798 | | - if isempty(args) |
799 | | - A = zeros(NT, length(i_b), 0) |
800 | | - else |
801 | | - A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max = args |
802 | | - A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max] |
803 | | - end |
804 | | - return i_b, i_g, A |
805 | | -end |
806 | | - |
807 | | -"Init `i_b, A` without outputs and terminal constraints if `model` is not a [`LinModel`](@ref)." |
808 | | -function init_matconstraint_mpc(::SimModel{NT}, |
809 | | - i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args... |
810 | | -) where {NT<:Real} |
811 | | - i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax] |
812 | | - i_g = [i_Ymin; i_Ymax; i_x̂min; i_x̂max] |
813 | | - if isempty(args) |
814 | | - A = zeros(NT, length(i_b), 0) |
815 | | - else |
816 | | - A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, _ , _ , _ , _ = args |
817 | | - A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax] |
818 | | - end |
819 | | - return i_b, i_g, A |
820 | | -end |
821 | | - |
822 | 823 | "Validate predictive controller weight and horizon specified values." |
823 | 824 | function validate_weights(model, Hp, Hc, M_Hp, N_Hc, L_Hp, C, E=nothing) |
824 | 825 | nu, ny = model.nu, model.ny |
|
0 commit comments