@@ -38,29 +38,35 @@ const InfoDictType = Union{JuMP._SolutionSummary, Vector{Float64}, Float64}
3838
3939" Include all the data for the constraints of [`PredictiveController`](@ref)"
4040struct 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}
6470end
6571
6672@doc raw """
@@ -198,7 +204,7 @@ function setconstraint!(
198204 model, con, optim = mpc. estim. model, mpc. con, mpc. optim
199205 nu, ny, nx̂, Hp, Hc = model. nu, model. ny, mpc. estim. nx̂, mpc. Hp, mpc. Hc
200206 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]
202208 isnothing (Umin) && ! isnothing (umin) && (Umin = repeat (umin, Hp))
203209 isnothing (Umax) && ! isnothing (umax) && (Umax = repeat (umax, Hp))
204210 isnothing (ΔUmin) && ! isnothing (Δumin) && (ΔUmin = repeat (Δumin, Hc))
@@ -604,7 +610,7 @@ the terminal constraints applied on ``\mathbf{x̂}_{k-1}(k+H_p)``.
604610function predict! (Ŷ, x̂, mpc:: PredictiveController , :: LinModel , ΔŨ:: Vector{T} ) where {T<: Real }
605611 # in-place operations to reduce allocations :
606612 mul! (Ŷ, mpc. Ẽ, ΔŨ) + mpc. F
607- mul! (x̂, mpc. ẽx̂, ΔŨ) + mpc. fx̂
613+ mul! (x̂, mpc. con . ẽx̂, ΔŨ) + mpc. con . fx̂
608614 x̂end = x̂
609615 return Ŷ, x̂end
610616end
@@ -640,17 +646,19 @@ Set `b` vector for the linear model inequality constraints (``\mathbf{A ΔŨ
640646Also init ``\m athbf{f_x̂}`` vector for the terminal constraints, see [`init_predmat`](@ref).
641647"""
642648function 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
645653 mpc. con. b[:] = [
646654 - mpc. con. Umin + mpc. T* (mpc. estim. lastu0 + model. uop)
647655 + mpc. con. Umax - mpc. T* (mpc. estim. lastu0 + model. uop)
648656 - mpc. con. ΔŨmin
649657 + mpc. con. ΔŨmax
650658 - mpc. con. Ymin + mpc. F
651659 + 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̂
654662 ]
655663 lincon:: LinConVector = mpc. optim[:linconstraint ]
656664 set_normalized_rhs .(lincon, mpc. con. b[mpc. con. i_b])
@@ -961,13 +969,13 @@ function obj_nonlinprog(
961969end
962970
963971"""
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, Ẽ
965973
966974Init `ControllerConstraint` struct with default parameters based on estimator `estim`.
967975
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 `ΔŨ`.
969977"""
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̂ )
971979 model = estim. model
972980 nu, ny, nx̂ = model. nu, model. ny, estim. nx̂
973981 umin, umax = fill (- Inf , nu), fill (+ Inf , nu)
@@ -997,11 +1005,12 @@ function init_defaultcon(estim, Hp, Hc, C, S, N_Hc, E, ex̂)
9971005 )
9981006 b = zeros (size (A, 1 )) # dummy b vector (updated just before optimization)
9991007 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 ,
10031012 )
1004- return con, S̃, Ñ_Hc, Ẽ, ẽx̂
1013+ return con, S̃, Ñ_Hc, Ẽ
10051014end
10061015
10071016" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
@@ -1126,10 +1135,26 @@ function relaxŶ(::SimModel, C, c_Ymin, c_Ymax, E)
11261135 return A_Ymin, A_Ymax, Ẽ
11271136end
11281137
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̂
11311140
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+ ```
11331158"""
11341159function relaxterminal (:: LinModel , C, c_x̂min, c_x̂max, ex̂)
11351160 if ! isinf (C) # ΔŨ = [ΔU; ϵ]
0 commit comments