Skip to content

Commit ff17732

Browse files
committed
doc: MHE constraint details
1 parent 6e8846a commit ff17732

File tree

8 files changed

+58
-31
lines changed

8 files changed

+58
-31
lines changed

docs/src/internals/predictive_control.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ The prediction methodology of this module is mainly based on Maciejowski textboo
1414
```@docs
1515
ModelPredictiveControl.init_predmat
1616
ModelPredictiveControl.init_ΔUtoU
17-
ModelPredictiveControl.init_quadprog_mpc
17+
ModelPredictiveControl.init_quadprog
1818
ModelPredictiveControl.init_stochpred
19-
ModelPredictiveControl.init_matconstraint
19+
ModelPredictiveControl.init_matconstraint_mpc
2020
```
2121

2222
## Constraint Relaxation

docs/src/internals/sim_model.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
Pages = ["sim_model.md"]
55
```
66

7-
## Steady-State Calculation
7+
## State-Space Functions
88

99
```@docs
10-
ModelPredictiveControl.steadystate!
10+
ModelPredictiveControl.f
11+
ModelPredictiveControl.h
1112
```
1213

13-
## State-Space Functions
14+
## Steady-State Calculation
1415

1516
```@docs
16-
ModelPredictiveControl.f
17-
ModelPredictiveControl.h
17+
ModelPredictiveControl.steadystate!
1818
```

docs/src/internals/state_estim.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Pages = ["state_estim.md"]
55
```
66

7+
## Augmented Model
8+
9+
```@docs
10+
ModelPredictiveControl.f̂
11+
ModelPredictiveControl.ĥ
12+
```
13+
714
## Estimator Construction
815

916
```@docs
@@ -12,13 +19,8 @@ ModelPredictiveControl.init_integrators
1219
ModelPredictiveControl.augment_model
1320
ModelPredictiveControl.init_ukf
1421
ModelPredictiveControl.init_internalmodel
15-
```
16-
17-
## Augmented Model
18-
19-
```@docs
20-
ModelPredictiveControl.f̂
21-
ModelPredictiveControl.ĥ
22+
ModelPredictiveControl.init_predmat_mhe
23+
ModelPredictiveControl.init_matconstraint_mhe
2224
```
2325

2426
## Evaluate Estimated Output

src/controller/explicitmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
4747
S, T = init_ΔUtoU(model, Hp, Hc)
4848
E, F, G, J, K, V = init_predmat(estim, model, Hp, Hc)
4949
S̃, Ñ_Hc, Ẽ = S, N_Hc, E # no slack variable ϵ for ExplicitMPC
50-
H̃, q̃, p = init_quadprog_mpc(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
50+
H̃, q̃, p = init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
5151
H̃_chol = cholesky(H̃)
5252
Ks, Ps = init_stochpred(estim, Hp)
5353
# dummy vals (updated just before optimization):

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct LinMPC{
5555
S, T = init_ΔUtoU(model, Hp, Hc)
5656
E, F, G, J, K, V, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂ = init_predmat(estim, model, Hp, Hc)
5757
con, S̃, Ñ_Hc, Ẽ = init_defaultcon_mpc(estim, Hp, Hc, Cwt, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂)
58-
H̃, q̃, p = init_quadprog_mpc(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
58+
H̃, q̃, p = init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
5959
Ks, Ps = init_stochpred(estim, Hp)
6060
# dummy vals (updated just before optimization):
6161
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct NonLinMPC{
5656
S, T = init_ΔUtoU(model, Hp, Hc)
5757
E, F, G, J, K, V, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂ = init_predmat(estim, model, Hp, Hc)
5858
con, S̃, Ñ_Hc, Ẽ = init_defaultcon_mpc(estim, Hp, Hc, Cwt, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂)
59-
H̃, q̃, p = init_quadprog_mpc(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
59+
H̃, q̃, p = init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
6060
Ks, Ps = init_stochpred(estim, Hp)
6161
# dummy vals (updated just before optimization):
6262
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)

src/estimator/mhe.jl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,16 +618,20 @@ end
618618
619619
Set the constraint parameters of `estim` [`MovingHorizonEstimator`](@ref).
620620
621-
The constraints of the moving horizon estimator are defined as:
621+
The moving horizon estimator supports constraints on the estimated states ``\mathbf{x̂}``,
622+
process noise ``\mathbf{ŵ}`` and sensor noise ``\mathbf{v̂}``:
622623
```math
623624
\begin{alignat*}{3}
624625
\mathbf{x̂_{min}} ≤&&\ \mathbf{x̂}_k(k-j+1) &≤ \mathbf{x̂_{max}} &&\qquad j = N_k, N_k - 1, ... , 0 \\
625626
\mathbf{ŵ_{min}} ≤&&\ \mathbf{ŵ}(k-j+1) &≤ \mathbf{ŵ_{max}} &&\qquad j = N_k, N_k - 1, ... , 1 \\
626627
\mathbf{v̂_{min}} ≤&&\ \mathbf{v̂}(k-j+1) &≤ \mathbf{v̂_{max}} &&\qquad j = N_k, N_k - 1, ... , 1
627628
\end{alignat*}
628629
```
629-
Note that state constraints are applied on the augmented state vector ``\mathbf{x̂}`` (see
630-
the extended help of [`SteadyKalmanFilter`](@ref) for details on augmentation).
630+
Note that state and process noise constraints are applied on augmented model vectors (see
631+
the extended help of [`SteadyKalmanFilter`](@ref) for details on augmentation). Also,
632+
constraining the estimated sensor noises is equivalent to constraining the innovation term
633+
since ``\mathbf{v̂}(k) = \mathbf{y^m}(k) - \mathbf{ŷ^m}(k)`` in the MHE. See Extended Help
634+
for time-varying constraints.
631635
632636
# Arguments
633637
!!! info
@@ -637,7 +641,11 @@ the extended help of [`SteadyKalmanFilter`](@ref) for details on augmentation).
637641
- `estim::MovingHorizonEstimator` : moving horizon estimator to set constraints.
638642
- `x̂min = fill(-Inf,nx̂)` : augmented state vector lower bounds ``\mathbf{x̂_{min}}``.
639643
- `x̂max = fill(+Inf,nx̂)` : augmented state vector upper bounds ``\mathbf{x̂_{max}}``.
640-
- all the keyword arguments above but with a capital letter, e.g. `X̂max` or `X̂min` : for
644+
- `ŵmin = fill(-Inf,nx̂)` : augmented process noise vector lower bounds ``\mathbf{ŵ_{min}}``.
645+
- `ŵmax = fill(+Inf,nx̂)` : augmented process noise vector upper bounds ``\mathbf{ŵ_{max}}``.
646+
- `v̂min = fill(-Inf,nym)` : sensor noise vector lower bounds ``\mathbf{v̂_{min}}``.
647+
- `v̂max = fill(+Inf,nym)` : sensor noise vector upper bounds ``\mathbf{v̂_{max}}``.
648+
- all the keyword arguments above but with a capital letter, e.g. `X̂max` or `V̂max` : for
641649
time-varying constraints (see Extended Help).
642650
643651
# Examples
@@ -653,6 +661,23 @@ MovingHorizonEstimator estimator with a sample time Ts = 1.0 s, LinModel and:
653661
0 unmeasured outputs yu
654662
0 measured disturbances d
655663
```
664+
665+
# Extended Help
666+
667+
For variable constraints, the bounds can be modified after calling [`updatestate!`](@ref),
668+
that is, at runtime, except for `±Inf` bounds. It is also possible to specify time-varying
669+
constraints over the horizon. In such a case, they are defined by:
670+
```math
671+
\begin{alignat*}{3}
672+
\mathbf{X̂_{min}} ≤&&\ \mathbf{X̂} &≤ \mathbf{X̂_{max}} \\
673+
\mathbf{Ŵ_{min}} ≤&&\ \mathbf{Ŵ} &≤ \mathbf{Ŵ_{max}} \\
674+
\mathbf{V̂_{min}} ≤&&\ \mathbf{V̂} &≤ \mathbf{V̂_{max}}
675+
\end{alignat*}
676+
```
677+
For this, use the same keyword arguments as above but with a capital letter:
678+
- `X̂min` / `X̂max` : ``\mathbf{X̂}`` constraints `(nx̂*(He+1),)`.
679+
- `Ŵmin` / `Ŵmax` : ``\mathbf{Ŵ}`` constraints `(nx̂*He,)`.
680+
- `V̂min` / `V̂max` : ``\mathbf{V̂}`` constraints `(nym*He,)`.
656681
"""
657682
function setconstraint!(
658683
estim::MovingHorizonEstimator;

src/predictive_control.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function setconstraint!(
299299
i_Ymin, i_Ymax = .!isinf.(con.Ymin), .!isinf.(con.Ymax)
300300
i_x̂min, i_x̂max = .!isinf.(con.x̂min), .!isinf.(con.x̂max)
301301
if notSolvedYet
302-
con.i_b[:], con.i_g[:], con.A[:] = init_matconstraint(model,
302+
con.i_b[:], con.i_g[:], con.A[:] = init_matconstraint_mpc(model,
303303
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax,
304304
i_Ymin, i_Ymax, i_x̂min, i_x̂max,
305305
con.A_Umin, con.A_Umax, con.A_ΔŨmin, con.A_ΔŨmax,
@@ -313,7 +313,7 @@ function setconstraint!(
313313
@constraint(optim, linconstraint, A*ΔŨvar .≤ b)
314314
setnonlincon!(mpc, model)
315315
else
316-
i_b, i_g = init_matconstraint(model,
316+
i_b, i_g = init_matconstraint_mpc(model,
317317
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax,
318318
i_Ymin, i_Ymax, i_x̂min, i_x̂max
319319
)
@@ -545,7 +545,7 @@ end
545545
546546
Init linear model prediction matrices `F, q̃, p` and current estimated output `ŷ`.
547547
548-
See [`init_predmat`](@ref) and [`init_quadprog_mpc`](@ref) for the definition of the matrices.
548+
See [`init_predmat`](@ref) and [`init_quadprog`](@ref) for the definition of the matrices.
549549
"""
550550
function initpred!(mpc::PredictiveController, model::LinModel, d, ym, D̂, R̂y, R̂u)
551551
mpc.ŷ[:] = evalŷ(mpc.estim, ym, d)
@@ -908,7 +908,7 @@ function init_predmat(estim::StateEstimator{NT}, model::SimModel, Hp, Hc) where
908908
end
909909

910910
@doc raw"""
911-
init_quadprog_mpc(model::LinModel, Ẽ, S, M_Hp, N_Hc, L_Hp) -> H̃, q̃, p
911+
init_quadprog(model::LinModel, Ẽ, S, M_Hp, N_Hc, L_Hp) -> H̃, q̃, p
912912
913913
Init the quadratic programming optimization matrix `H̃` and `q̃` for MPC.
914914
@@ -921,14 +921,14 @@ vector ``\mathbf{q̃}`` and scalar ``p`` need recalculation each control period
921921
[`initpred!`](@ref) method). ``p`` does not impact the minima position. It is thus
922922
useless at optimization but required to evaluate the minimal ``J`` value.
923923
"""
924-
function init_quadprog_mpc(::LinModel{NT}, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp) where {NT<:Real}
924+
function init_quadprog(::LinModel{NT}, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp) where {NT<:Real}
925925
= Hermitian(convert(Matrix{NT}, 2*(Ẽ'*M_Hp*+ Ñ_Hc +'*L_Hp*S̃)), :L)
926926
= zeros(NT, size(H̃, 1)) # dummy value (updated just before optimization)
927927
p = zeros(NT, 1) # dummy value (updated just before optimization)
928928
return H̃, q̃, p
929929
end
930930
"Return empty matrices if `model` is not a [`LinModel`](@ref)."
931-
function init_quadprog_mpc(::SimModel{NT}, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp) where {NT<:Real}
931+
function init_quadprog(::SimModel{NT}, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp) where {NT<:Real}
932932
= Hermitian(zeros(NT, 0, 0))
933933
= zeros(NT, 0)
934934
p = zeros(NT, 1) # dummy value (updated just before optimization)
@@ -1026,7 +1026,7 @@ function init_defaultcon_mpc(
10261026
i_ΔŨmin, i_ΔŨmax = .!isinf.(ΔŨmin), .!isinf.(ΔŨmax)
10271027
i_Ymin, i_Ymax = .!isinf.(Ymin), .!isinf.(Ymax)
10281028
i_x̂min, i_x̂max = .!isinf.(x̂min), .!isinf.(x̂max)
1029-
i_b, i_g, A = init_matconstraint(
1029+
i_b, i_g, A = init_matconstraint_mpc(
10301030
model,
10311031
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
10321032
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂max, A_x̂min
@@ -1246,7 +1246,7 @@ function init_stochpred(estim::StateEstimator{NT}, _ ) where NT<:Real
12461246
end
12471247

12481248
@doc raw"""
1249-
init_matconstraint(model::LinModel,
1249+
init_matconstraint_mpc(model::LinModel,
12501250
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
12511251
) -> i_b, i_g, A
12521252
@@ -1265,7 +1265,7 @@ The linear and nonlinear inequality constraints are respectively defined as:
12651265
provided. In such a case, `args` needs to contain all the inequality constraint matrices:
12661266
`A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max`.
12671267
"""
1268-
function init_matconstraint(::LinModel{NT},
1268+
function init_matconstraint_mpc(::LinModel{NT},
12691269
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
12701270
) where {NT<:Real}
12711271
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max]
@@ -1280,7 +1280,7 @@ function init_matconstraint(::LinModel{NT},
12801280
end
12811281

12821282
"Init `i_b, A` without outputs and terminal constraints if `model` is not a [`LinModel`](@ref)."
1283-
function init_matconstraint(::SimModel{NT},
1283+
function init_matconstraint_mpc(::SimModel{NT},
12841284
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
12851285
) where {NT<:Real}
12861286
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax]

0 commit comments

Comments
 (0)