11struct PredictiveControllerBuffer{NT<: Real }
2- u:: Vector{NT}
3- Z̃:: Vector{NT}
4- D̂:: Vector{NT}
5- Ŷ:: Vector{NT}
6- U:: Vector{NT}
7- Ẽ:: Matrix{NT}
8- S̃ :: Matrix{NT}
2+ u :: Vector{NT}
3+ Z̃ :: Vector{NT}
4+ D̂ :: Vector{NT}
5+ Ŷ :: Vector{NT}
6+ U :: Vector{NT}
7+ Ẽ :: Matrix{NT}
8+ P̃U :: Matrix{NT}
99 empty:: Vector{NT}
1010end
1111
@@ -21,15 +21,15 @@ function PredictiveControllerBuffer(
2121) where NT <: Real
2222 nu, ny, nd, nx̂ = estim. model. nu, estim. model. ny, estim. model. nd, estim. nx̂
2323 nZ̃ = get_nZ (estim, transcription, Hp, Hc) + nϵ
24- u = Vector {NT} (undef, nu)
25- Z̃ = Vector {NT} (undef, nZ̃)
26- D̂ = Vector {NT} (undef, nd* Hp)
27- Ŷ = Vector {NT} (undef, ny* Hp)
28- U = Vector {NT} (undef, nu* Hp)
29- Ẽ = Matrix {NT} (undef, ny* Hp, nZ̃)
30- S̃ = Matrix {NT} (undef, nu* Hp, nZ̃)
24+ u = Vector {NT} (undef, nu)
25+ Z̃ = Vector {NT} (undef, nZ̃)
26+ D̂ = Vector {NT} (undef, nd* Hp)
27+ Ŷ = Vector {NT} (undef, ny* Hp)
28+ U = Vector {NT} (undef, nu* Hp)
29+ Ẽ = Matrix {NT} (undef, ny* Hp, nZ̃)
30+ P̃U = Matrix {NT} (undef, nu* Hp, nZ̃)
3131 empty = Vector {NT} (undef, 0 )
32- return PredictiveControllerBuffer {NT} (u, Z̃, D̂, Ŷ, U, Ẽ, S̃ , empty)
32+ return PredictiveControllerBuffer {NT} (u, Z̃, D̂, Ŷ, U, Ẽ, P̃U , empty)
3333end
3434
3535" Include all the objective function weights of [`PredictiveController`](@ref)"
@@ -526,7 +526,7 @@ function validate_args(mpc::PredictiveController, ry, d, D̂, R̂y, R̂u)
526526end
527527
528528@doc raw """
529- init_quadprog(model::LinModel, weights::ControllerWeights, Ẽ, P̃, S̃ ) -> H̃
529+ init_quadprog(model::LinModel, weights::ControllerWeights, Ẽ, P̃ΔU, P̃U ) -> H̃
530530
531531Init the quadratic programming Hessian `H̃` for MPC.
532532
@@ -536,17 +536,17 @@ The matrix appear in the quadratic general form:
536536```
537537The Hessian matrix is constant if the model and weights are linear and time invariant (LTI):
538538```math
539- \m athbf{H̃} = 2 ( \m athbf{Ẽ}'\m athbf{M}_{H_p}\m athbf{Ẽ}
540- + \m athbf{P̃}' \m athbf{Ñ}_{H_c}\m athbf{P̃ }
541- + \m athbf{S̃}' \m athbf{L}_{H_p}\m athbf{S̃} )
539+ \m athbf{H̃} = 2 ( \m athbf{Ẽ}' \m athbf{M}_{H_p} \m athbf{Ẽ}
540+ + \m athbf{P̃_{ΔU}}' \m athbf{Ñ}_{H_c} \m athbf{P̃_{ΔU} }
541+ + \m athbf{P̃_{U}}' \m athbf{L}_{H_p} \m athbf{P̃_{U}} )
542542```
543543The vector ``\m athbf{q̃}`` and scalar ``r`` need recalculation each control period ``k``, see
544544[`initpred!`](@ref). ``r`` does not impact the minima position. It is thus useless at
545545optimization but required to evaluate the minimal ``J`` value.
546546"""
547- function init_quadprog (:: LinModel , weights:: ControllerWeights , Ẽ, P̃, S̃ )
547+ function init_quadprog (:: LinModel , weights:: ControllerWeights , Ẽ, P̃ΔU, P̃U )
548548 M_Hp, Ñ_Hc, L_Hp = weights. M_Hp, weights. Ñ_Hc, weights. L_Hp
549- H̃ = Hermitian (2 * (Ẽ' * M_Hp* Ẽ + P̃ ' * Ñ_Hc* P̃ + S̃ ' * L_Hp* S̃ ), :L )
549+ H̃ = Hermitian (2 * (Ẽ' * M_Hp* Ẽ + P̃ΔU ' * Ñ_Hc* P̃ΔU + P̃U ' * L_Hp* P̃U ), :L )
550550 return H̃
551551end
552552" Return empty matrix if `model` is not a [`LinModel`](@ref)."
@@ -559,20 +559,20 @@ end
559559 init_defaultcon_mpc(
560560 estim::StateEstimator, transcription::TranscriptionMethod,
561561 Hp, Hc, C,
562- P, S , E,
562+ PΔU, PU , E,
563563 ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
564564 Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
565565 gc!=nothing, nc=0
566- ) -> con, S̃ , Ẽ, Ẽŝ
566+ ) -> con, nϵ, P̃ΔU, P̃U , Ẽ, Ẽŝ
567567
568568Init `ControllerConstraint` struct with default parameters based on estimator `estim`.
569569
570- Also return `P̃ `, `S̃ `, `Ẽ` and `Ẽŝ` matrices for the the augmented decision vector `Z̃`.
570+ Also return `P̃ΔU `, `P̃U `, `Ẽ` and `Ẽŝ` matrices for the the augmented decision vector `Z̃`.
571571"""
572572function init_defaultcon_mpc (
573573 estim:: StateEstimator{NT} , transcription:: TranscriptionMethod ,
574- Hp, Hc, C,
575- P, S , E,
574+ Hp, Hc, C,
575+ PΔU, PU , E,
576576 ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
577577 Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
578578 gc!:: GCfunc = nothing , nc = 0
@@ -592,8 +592,8 @@ function init_defaultcon_mpc(
592592 repeat_constraints (Hp, Hc, u0min, u0max, Δumin, Δumax, y0min, y0max)
593593 C_umin, C_umax, C_Δumin, C_Δumax, C_ymin, C_ymax =
594594 repeat_constraints (Hp, Hc, c_umin, c_umax, c_Δumin, c_Δumax, c_ymin, c_ymax)
595- A_Umin, A_Umax, S̃ = relaxU (S , C_umin, C_umax, nϵ)
596- A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ = relaxΔU (P , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ)
595+ A_Umin, A_Umax, P̃U = relaxU (PU , C_umin, C_umax, nϵ)
596+ A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU = relaxΔU (PΔU , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ)
597597 A_Ymin, A_Ymax, Ẽ = relaxŶ (E, C_ymin, C_ymax, nϵ)
598598 A_x̂min, A_x̂max, ẽx̂ = relaxterminal (ex̂, c_x̂min, c_x̂max, nϵ)
599599 A_ŝ, Ẽŝ = augmentdefect (Eŝ, nϵ)
@@ -620,7 +620,7 @@ function init_defaultcon_mpc(
620620 C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
621621 gc! , nc
622622 )
623- return con, nϵ, P̃, S̃ , Ẽ, Ẽŝ
623+ return con, nϵ, P̃ΔU, P̃U , Ẽ, Ẽŝ
624624end
625625
626626" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
@@ -635,13 +635,13 @@ function repeat_constraints(Hp, Hc, umin, umax, Δumin, Δumax, ymin, ymax)
635635end
636636
637637@doc raw """
638- relaxU(S , C_umin, C_umax, nϵ) -> A_Umin, A_Umax, S̃
638+ relaxU(PU , C_umin, C_umax, nϵ) -> A_Umin, A_Umax, P̃U
639639
640640Augment manipulated inputs constraints with slack variable ϵ for softening.
641641
642642Denoting the decision variables augmented with the slack variable
643643``\m athbf{Z̃} = [\b egin{smallmatrix} \m athbf{Z} \\ ϵ \e nd{smallmatrix}]``, it returns the
644- augmented conversion matrix ``\m athbf{S̃ }``, similar to the one described at
644+ augmented conversion matrix ``\m athbf{P̃U }``, similar to the one described at
645645[`init_ZtoU`](@ref). It also returns the ``\m athbf{A}`` matrices for the inequality
646646constraints:
647647```math
@@ -650,36 +650,36 @@ constraints:
650650 \m athbf{A_{U_{max}}}
651651\e nd{bmatrix} \m athbf{Z̃} ≤
652652\b egin{bmatrix}
653- - \m athbf{U_{min} + T u}(k-1) \\
654- + \m athbf{U_{max} - T u}(k-1)
653+ - \m athbf{U_{min} + T_U u}(k-1) \\
654+ + \m athbf{U_{max} - T_U u}(k-1)
655655\e nd{bmatrix}
656656```
657657in which ``\m athbf{U_{min}}`` and ``\m athbf{U_{max}}`` vectors respectively contains
658658``\m athbf{u_{min}}`` and ``\m athbf{u_{max}}`` repeated ``H_p`` times.
659659"""
660- function relaxU (S :: Matrix{NT} , C_umin, C_umax, nϵ) where NT<: Real
660+ function relaxU (PU :: Matrix{NT} , C_umin, C_umax, nϵ) where NT<: Real
661661 if nϵ == 1 # Z̃ = [Z; ϵ]
662662 # ϵ impacts Z → U conversion for constraint calculations:
663- A_Umin, A_Umax = - [S C_umin], [S - C_umax]
663+ A_Umin, A_Umax = - [PU C_umin], [PU - C_umax]
664664 # ϵ has no impact on Z → U conversion for prediction calculations:
665- S̃ = [S zeros (NT, size (S , 1 ))]
665+ P̃U = [PU zeros (NT, size (PU , 1 ))]
666666 else # Z̃ = Z (only hard constraints)
667- A_Umin, A_Umax = - S , S
668- S̃ = S
667+ A_Umin, A_Umax = - PU , PU
668+ P̃U = PU
669669 end
670- return A_Umin, A_Umax, S̃
670+ return A_Umin, A_Umax, P̃U
671671end
672672
673673@doc raw """
674- relaxΔU(P , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃
674+ relaxΔU(PΔU , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU
675675
676676Augment input increments constraints with slack variable ϵ for softening.
677677
678678Denoting the decision variables augmented with the slack variable
679679``\m athbf{Z̃} = [\b egin{smallmatrix} \m athbf{Z} \\ ϵ \e nd{smallmatrix}]``, it returns the
680- augmented conversion matrix ``\m athbf{P̃ }``, similar to the one described at
680+ augmented conversion matrix ``\m athbf{P̃_{ΔU} }``, similar to the one described at
681681[`init_ZtoΔU`](@ref), but extracting the input increments augmented with the slack variable
682- ``\m athbf{ΔŨ} = [\b egin{smallmatrix} \m athbf{ΔU} \\ ϵ \e nd{smallmatrix}] = \m athbf{P̃ Z̃}``.
682+ ``\m athbf{ΔŨ} = [\b egin{smallmatrix} \m athbf{ΔU} \\ ϵ \e nd{smallmatrix}] = \m athbf{P̃_{ΔU} Z̃}``.
683683Also, knowing that ``0 ≤ ϵ ≤ ∞``, it also returns the augmented bounds
684684``\m athbf{ΔŨ_{min}} = [\b egin{smallmatrix} \m athbf{ΔU_{min}} \\ 0 \e nd{smallmatrix}]`` and
685685``\m athbf{ΔŨ_{max}} = [\b egin{smallmatrix} \m athbf{ΔU_{min}} \\ ∞ \e nd{smallmatrix}]``,
@@ -695,23 +695,23 @@ and the ``\mathbf{A}`` matrices for the inequality constraints:
695695\e nd{bmatrix}
696696```
697697Note that strictly speaking, the lower bound on the slack variable ϵ is a decision variable
698- bound, which is more specific than a linear inequality constraint. However, it is more
698+ bound, which is more precise than a linear inequality constraint. However, it is more
699699convenient to treat it as a linear inequality constraint since the optimizer `OSQP.jl` does
700700not support pure bounds on the decision variables.
701701"""
702- function relaxΔU (P :: Matrix{NT} , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<: Real
703- nZ = size (P , 2 )
702+ function relaxΔU (PΔU :: Matrix{NT} , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<: Real
703+ nZ = size (PΔU , 2 )
704704 if nϵ == 1 # Z̃ = [Z; ϵ]
705705 ΔŨmin, ΔŨmax = [ΔUmin; NT[0.0 ]], [ΔUmax; NT[Inf ]] # 0 ≤ ϵ ≤ ∞
706706 A_ϵ = [zeros (NT, 1 , nZ) NT[1.0 ]]
707- A_ΔŨmin, A_ΔŨmax = - [P C_Δumin; A_ϵ], [P - C_Δumax; A_ϵ]
708- P̃ = [P zeros (NT, size (P , 1 ), 1 ); zeros (NT, 1 , size (P , 2 )) NT[1.0 ]]
707+ A_ΔŨmin, A_ΔŨmax = - [PΔU C_Δumin; A_ϵ], [PΔU - C_Δumax; A_ϵ]
708+ P̃ΔU = [PΔU zeros (NT, size (PΔU , 1 ), 1 ); zeros (NT, 1 , size (PΔU , 2 )) NT[1.0 ]]
709709 else # Z̃ = Z (only hard constraints)
710710 ΔŨmin, ΔŨmax = ΔUmin, ΔUmax
711- A_ΔŨmin, A_ΔŨmax = - P , P
712- P̃ = P
711+ A_ΔŨmin, A_ΔŨmax = - PΔU , PΔU
712+ P̃ΔU = PΔU
713713 end
714- return A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃
714+ return A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃ΔU
715715end
716716
717717@doc raw """
0 commit comments