@@ -38,29 +38,35 @@ const InfoDictType = Union{JuMP._SolutionSummary, Vector{Float64}, Float64}
38
38
39
39
" Include all the data for the constraints of [`PredictiveController`](@ref)"
40
40
struct ControllerConstraint
41
- Umin :: Vector{Float64}
42
- Umax :: Vector{Float64}
43
- ΔŨmin :: Vector{Float64}
44
- ΔŨmax :: Vector{Float64}
45
- Ymin :: Vector{Float64}
46
- Ymax :: Vector{Float64}
47
- x̂min :: Vector{Float64}
48
- x̂max :: Vector{Float64}
49
- A_Umin :: Matrix{Float64}
50
- A_Umax :: Matrix{Float64}
51
- A_ΔŨmin:: Matrix{Float64}
52
- A_ΔŨmax:: Matrix{Float64}
53
- A_Ymin :: Matrix{Float64}
54
- A_Ymax :: Matrix{Float64}
55
- A_x̂min :: Matrix{Float64}
56
- A_x̂max :: Matrix{Float64}
57
- A :: Matrix{Float64}
58
- b :: Vector{Float64}
59
- i_b :: BitVector
60
- c_Ymin :: Vector{Float64}
61
- c_Ymax :: Vector{Float64}
62
- c_x̂min :: Vector{Float64}
63
- c_x̂max :: Vector{Float64}
41
+ ẽx̂ :: Matrix{Float64}
42
+ fx̂ :: Vector{Float64}
43
+ gx̂ :: Matrix{Float64}
44
+ jx̂ :: Matrix{Float64}
45
+ kx̂ :: Matrix{Float64}
46
+ vx̂ :: Matrix{Float64}
47
+ Umin :: Vector{Float64}
48
+ Umax :: Vector{Float64}
49
+ ΔŨmin :: Vector{Float64}
50
+ ΔŨmax :: Vector{Float64}
51
+ Ymin :: Vector{Float64}
52
+ Ymax :: Vector{Float64}
53
+ x̂min :: Vector{Float64}
54
+ x̂max :: Vector{Float64}
55
+ A_Umin :: Matrix{Float64}
56
+ A_Umax :: Matrix{Float64}
57
+ A_ΔŨmin :: Matrix{Float64}
58
+ A_ΔŨmax :: Matrix{Float64}
59
+ A_Ymin :: Matrix{Float64}
60
+ A_Ymax :: Matrix{Float64}
61
+ A_x̂min :: Matrix{Float64}
62
+ A_x̂max :: Matrix{Float64}
63
+ A :: Matrix{Float64}
64
+ b :: Vector{Float64}
65
+ i_b :: BitVector
66
+ c_Ymin :: Vector{Float64}
67
+ c_Ymax :: Vector{Float64}
68
+ c_x̂min :: Vector{Float64}
69
+ c_x̂max :: Vector{Float64}
64
70
end
65
71
66
72
@doc raw """
@@ -198,7 +204,7 @@ function setconstraint!(
198
204
model, con, optim = mpc. estim. model, mpc. con, mpc. optim
199
205
nu, ny, nx̂, Hp, Hc = model. nu, model. ny, mpc. estim. nx̂, mpc. Hp, mpc. Hc
200
206
notSolvedYet = (termination_status (optim) == OPTIMIZE_NOT_CALLED)
201
- C, E, ex̂ = mpc. C, mpc. Ẽ[:, 1 : nu* Hc], mpc. ẽx̂[:, 1 : nu* Hc]
207
+ C, E, ex̂ = mpc. C, mpc. Ẽ[:, 1 : nu* Hc], mpc. con . ẽx̂[:, 1 : nu* Hc]
202
208
isnothing (Umin) && ! isnothing (umin) && (Umin = repeat (umin, Hp))
203
209
isnothing (Umax) && ! isnothing (umax) && (Umax = repeat (umax, Hp))
204
210
isnothing (ΔUmin) && ! isnothing (Δumin) && (ΔUmin = repeat (Δumin, Hc))
@@ -604,7 +610,7 @@ the terminal constraints applied on ``\mathbf{x̂}_{k-1}(k+H_p)``.
604
610
function predict! (Ŷ, x̂, mpc:: PredictiveController , :: LinModel , ΔŨ:: Vector{T} ) where {T<: Real }
605
611
# in-place operations to reduce allocations :
606
612
mul! (Ŷ, mpc. Ẽ, ΔŨ) + mpc. F
607
- mul! (x̂, mpc. ẽx̂, ΔŨ) + mpc. fx̂
613
+ mul! (x̂, mpc. con . ẽx̂, ΔŨ) + mpc. con . fx̂
608
614
x̂end = x̂
609
615
return Ŷ, x̂end
610
616
end
@@ -640,17 +646,19 @@ Set `b` vector for the linear model inequality constraints (``\mathbf{A ΔŨ
640
646
Also init ``\m athbf{f_x̂}`` vector for the terminal constraints, see [`init_predmat`](@ref).
641
647
"""
642
648
function linconstraint! (mpc:: PredictiveController , model:: LinModel )
643
- mpc. fx̂[:] = mpc. kx̂ * mpc. estim. x̂ + mpc. vx̂ * mpc. estim. lastu0
644
- mpc. fx̂[:] = model. nd ≠ 0 ? mpc. fx̂ + mpc. gx̂ * mpc. d0 + mpc. jx̂ * mpc. D̂0 : mpc. fx̂
649
+ mpc. con. fx̂[:] = mpc. con. kx̂ * mpc. estim. x̂ + mpc. con. vx̂ * mpc. estim. lastu0
650
+ if model. nd ≠ 0
651
+ mpc. con. fx̂[:] = mpc. con. fx̂ + mpc. con. gx̂ * mpc. d0 + mpc. con. jx̂ * mpc. D̂0
652
+ end
645
653
mpc. con. b[:] = [
646
654
- mpc. con. Umin + mpc. T* (mpc. estim. lastu0 + model. uop)
647
655
+ mpc. con. Umax - mpc. T* (mpc. estim. lastu0 + model. uop)
648
656
- mpc. con. ΔŨmin
649
657
+ mpc. con. ΔŨmax
650
658
- mpc. con. Ymin + mpc. F
651
659
+ mpc. con. Ymax - mpc. F
652
- - mpc. con. x̂min + mpc. fx̂
653
- + mpc. con. x̂max - mpc. fx̂
660
+ - mpc. con. x̂min + mpc. con . fx̂
661
+ + mpc. con. x̂max - mpc. con . fx̂
654
662
]
655
663
lincon:: LinConVector = mpc. optim[:linconstraint ]
656
664
set_normalized_rhs .(lincon, mpc. con. b[mpc. con. i_b])
@@ -961,13 +969,13 @@ function obj_nonlinprog(
961
969
end
962
970
963
971
"""
964
- init_defaultcon(estim, C, S, N_Hc, E, ex̂) -> con, S̃, Ñ_Hc, Ẽ, ẽx̂
972
+ init_defaultcon(estim, C, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂ ) -> con, S̃, Ñ_Hc, Ẽ
965
973
966
974
Init `ControllerConstraint` struct with default parameters based on estimator `estim`.
967
975
968
- Also return `S̃`, `Ñ_Hc`, `Ẽ` and ẽx̂ matrices for the the augmented decision vector `ΔŨ`.
976
+ Also return `S̃`, `Ñ_Hc` and `Ẽ` matrices for the the augmented decision vector `ΔŨ`.
969
977
"""
970
- function init_defaultcon (estim, Hp, Hc, C, S, N_Hc, E, ex̂)
978
+ function init_defaultcon (estim, Hp, Hc, C, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂ )
971
979
model = estim. model
972
980
nu, ny, nx̂ = model. nu, model. ny, estim. nx̂
973
981
umin, umax = fill (- Inf , nu), fill (+ Inf , nu)
@@ -997,11 +1005,12 @@ function init_defaultcon(estim, Hp, Hc, C, S, N_Hc, E, ex̂)
997
1005
)
998
1006
b = zeros (size (A, 1 )) # dummy b vector (updated just before optimization)
999
1007
con = ControllerConstraint (
1000
- Umin , Umax , ΔŨmin , ΔŨmax , Ymin , Ymax, x̂min, x̂max,
1001
- A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin, A_Ymax, A_x̂min, A_x̂max,
1002
- A , b , i_b , c_Ymin , c_Ymax, c_x̂min, c_x̂max,
1008
+ ẽx̂ , fx̂ , gx̂ , jx̂ , kx̂ , vx̂ ,
1009
+ Umin , Umax , ΔŨmin , ΔŨmax , Ymin , Ymax , x̂min , x̂max,
1010
+ A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
1011
+ A , b , i_b , c_Ymin , c_Ymax , c_x̂min , c_x̂max ,
1003
1012
)
1004
- return con, S̃, Ñ_Hc, Ẽ, ẽx̂
1013
+ return con, S̃, Ñ_Hc, Ẽ
1005
1014
end
1006
1015
1007
1016
" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
@@ -1126,10 +1135,26 @@ function relaxŶ(::SimModel, C, c_Ymin, c_Ymax, E)
1126
1135
return A_Ymin, A_Ymax, Ẽ
1127
1136
end
1128
1137
1129
- """
1130
- relaxterminal(::LinModel, C, c_x̂min, c_x̂max, ex̂)
1138
+ @doc raw """
1139
+ relaxterminal(::LinModel, C, c_x̂min, c_x̂max, ex̂) -> A_x̂min, A_x̂max, ẽx̂
1131
1140
1132
- TBW
1141
+ Augment terminal state constraints with slack variable ϵ for softening.
1142
+
1143
+ Denoting the input increments augmented with the slack variable
1144
+ ``\m athbf{ΔŨ} = [\b egin{smallmatrix} \m athbf{ΔU} \\ ϵ \e nd{smallmatrix}]``, it returns the
1145
+ ``\m athbf{ẽ_{x̂}}`` matrix that appears in the terminal state equation
1146
+ ``\m athbf{x̂}_{k-1}(k + H_p) = \m athbf{ẽ_x̂ ΔŨ + f_x̂}``, and the ``\m athbf{A}`` matrices for
1147
+ the inequality constraints:
1148
+ ```math
1149
+ \b egin{bmatrix}
1150
+ \m athbf{A_{x̂_{min}}} \\
1151
+ \m athbf{A_{x̂_{max}}}
1152
+ \e nd{bmatrix} \m athbf{ΔŨ} ≤
1153
+ \b egin{bmatrix}
1154
+ - \m athbf{x̂_{min}} + \m athbf{f_x̂} \\
1155
+ + \m athbf{x̂_{max}} - \m athbf{f_x̂}
1156
+ \e nd{bmatrix}
1157
+ ```
1133
1158
"""
1134
1159
function relaxterminal (:: LinModel , C, c_x̂min, c_x̂max, ex̂)
1135
1160
if ! isinf (C) # ΔŨ = [ΔU; ϵ]
0 commit comments