Skip to content

Commit 837675b

Browse files
committed
debug: ambiguous methods
1 parent 2fcec1e commit 837675b

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

docs/src/internals/predictive_control.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ ModelPredictiveControl.relaxŶ
2828
ModelPredictiveControl.relaxterminal
2929
```
3030

31-
## Predictions
32-
33-
```@docs
34-
ModelPredictiveControl.initpred!
35-
```
36-
3731
## Constraints
3832

3933
```@docs

src/estimator/mhe.jl

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ and the covariances are repeated ``N_k`` times:
173173
```
174174
The estimation horizon ``H_e`` limits the window length:
175175
```math
176-
N_k = \min(k+1, H_e)
176+
N_k = \begin{cases}
177+
k + 1 & k < H_e \\
178+
H_e & k ≥ H_e \end{cases}
177179
```
178180
The vectors ``\mathbf{Ŵ}`` and ``\mathbf{V̂}`` encompass the estimated process noise
179181
``\mathbf{ŵ}(k-j)`` and sensor noise ``\mathbf{v̂}(k-j)`` from ``j=N_k-1`` to ``0``. The
@@ -228,12 +230,15 @@ The estimated process and sensor noises are defined as:
228230
\mathbf{v̂}(k)
229231
\end{bmatrix}
230232
```
231-
in which ``\mathbf{v̂}(k-j) =
232-
\mathbf{y^m}(k-j) - \mathbf{ĥ^m}\big(\mathbf{x̂}_k(k-j), \mathbf{d}(k-j)\big)`` from ``j =
233-
N_k-1`` to ``0``. The augmented model ``\mathbf{f̂}`` with the process noise recursively
234-
generates the state estimates ``\mathbf{x̂}_k(k-j+1) =
235-
\mathbf{f̂}\big(\mathbf{x̂}_k(k-j), \mathbf{u}(k-j), \mathbf{d}(k-j)\big) + \mathbf{ŵ}(k-j)``
236-
from ``j=N_k-1`` to ``0``.
233+
based on the augmented model ``\mathbf{f̂, ĥ^m}``:
234+
```math
235+
\begin{aligned}
236+
\mathbf{x̂}_k(k-j+1) &= \mathbf{f̂}\Big(\mathbf{x̂}_k(k-j), \mathbf{u}(k-j), \mathbf{d}(k-j)\Big)
237+
+ \mathbf{ŵ}(k-j) \\
238+
\mathbf{v̂}(k-j) &= \mathbf{y^m}(k-j)
239+
- \mathbf{ĥ^m}\Big(\mathbf{x̂}_k(k-j), \mathbf{d}(k-j)\Big)
240+
\end{aligned}
241+
```
237242
"""
238243
function MovingHorizonEstimator(
239244
model::SM;
@@ -343,30 +348,34 @@ function relaxV̂(::SimModel{NT}, E) where {NT<:Real}
343348
end
344349

345350
@doc raw"""
346-
init_predmat_mhe(model::LinModel{NT}, He, i_ym, Â, B̂u, Ĉ, B̂d, D̂d) -> E, F, G, J, ex̄, fx̄
351+
init_predmat_mhe(
352+
model::LinModel{NT}, He, i_ym, Â, B̂u, Ĉ, B̂d, D̂d
353+
) -> E, F, G, J, ex̄, fx̄, Ex̂, Fx̂, Gx̂, Jx̂
347354
348355
Construct the MHE prediction matrices for [`LinModel`](@ref) `model`.
349356
350357
Introducing the vector ``\mathbf{Z} = [\begin{smallmatrix} \mathbf{x̂_k}(k-H_e+1)
351-
\\ \mathbf{Ŵ} \begin{smallmatrix}]`` with the decision variables, the estimated sensor
358+
\\ \mathbf{Ŵ} \end{smallmatrix}]`` with the decision variables, the estimated sensor
352359
noises from time ``k-H_e+1`` to ``k`` are computed by:
353360
```math
354361
\begin{aligned}
355-
\mathbf{V̂} = \mathbf{Y^m - Ŷ^m} &= \mathbf{E Z + G U + J D + Y^m} \\
356-
&= \mathbf{E Z + F}
362+
\mathbf{V̂} = \mathbf{Y^m - Ŷ^m} &= \mathbf{E Z + G U + J D + Y^m} \\
363+
&= \mathbf{E Z + F}
357364
\end{aligned}
358-
in which ``U``, ``D`` and ``Y^m`` contains respectively the manipulated inputs and measured
359-
disturbances and measured outputs from time ``k-H_e+1`` to ``k``. The method also returns
360-
similar matrices but for the estimation error at arrival:
365+
```
366+
in which ``\mathbf{U, D}`` and ``\mathbf{Y^m}`` contains respectively the manipulated inputs
367+
and measured disturbances and measured outputs from time ``k-H_e+1`` to ``k``. The method
368+
also returns similar matrices but for the estimation error at arrival:
361369
```math
362-
\mathbf{x̄} = \mathbf{x̂}_{k-He}(k-H_e+1) - \mathbf{x̂}_{k}(k-H_e+1) = \mathbf{e_x̄ Z + f_x̄}
370+
\mathbf{x̄} = \mathbf{x̂}_{k-H_e}(k-H_e+1) - \mathbf{x̂}_{k}(k-H_e+1) = \mathbf{e_x̄ Z + f_x̄}
363371
```
364372
Lastly, the estimated states from time ``k-H_e+2`` to ``k+1`` are given by the equation:
365373
```math
366374
\begin{aligned}
367-
\mathbf{X̂} &= \mathbf{E_x̂ Z + G_x̂ U + J_x̂ D} \\
368-
&= \mathbf{E_x̂ Z + F_x̂}
375+
\mathbf{X̂} &= \mathbf{E_x̂ Z + G_x̂ U + J_x̂ D} \\
376+
&= \mathbf{E_x̂ Z + F_x̂}
369377
\end{aligned}
378+
```
370379
All these equations omit the operating points ``\mathbf{u_{op}, y_{op}, d_{op}}``. These
371380
matrices are truncated when ``N_k < H_e`` (at the beginning).
372381
@@ -377,7 +386,7 @@ for the sensor noises are computed by (notice the minus signs after the equaliti
377386
\begin{aligned}
378387
\mathbf{E} &= - \begin{bmatrix}
379388
\mathbf{Ĉ^m}\mathbf{A}^{0} & \mathbf{0} & \cdots & \mathbf{0} \\
380-
\mathbf{Ĉ^m}\mathbf{Â}^{1} & \mathbf{Ĉ^m} & \cdots & \mathbf{0} \\
389+
\mathbf{Ĉ^m}\mathbf{Â}^{1} & \mathbf{Ĉ^m}\mathbf{A}^{0} & \cdots & \mathbf{0} \\
381390
\vdots & \vdots & \ddots & \vdots \\
382391
\mathbf{Ĉ^m}\mathbf{Â}^{H_e-1} & \mathbf{Ĉ^m}\mathbf{Â}^{H_e-2} & \cdots & \mathbf{0} \end{bmatrix} \\
383392
\mathbf{G} &= - \begin{bmatrix}
@@ -649,12 +658,12 @@ for time-varying constraints.
649658
will not re-assign to its default value (defaults are set at construction only).
650659
651660
- `estim::MovingHorizonEstimator` : moving horizon estimator to set constraints.
652-
- `x̂min = fill(-Inf,nx̂)` : augmented state vector lower bounds ``\mathbf{x̂_{min}}``.
653-
- `x̂max = fill(+Inf,nx̂)` : augmented state vector upper bounds ``\mathbf{x̂_{max}}``.
654-
- `ŵmin = fill(-Inf,nx̂)` : augmented process noise vector lower bounds ``\mathbf{ŵ_{min}}``.
655-
- `ŵmax = fill(+Inf,nx̂)` : augmented process noise vector upper bounds ``\mathbf{ŵ_{max}}``.
656-
- `v̂min = fill(-Inf,nym)` : sensor noise vector lower bounds ``\mathbf{v̂_{min}}``.
657-
- `v̂max = fill(+Inf,nym)` : sensor noise vector upper bounds ``\mathbf{v̂_{max}}``.
661+
- `x̂min = fill(-Inf,nx̂)` : augmented state lower bounds ``\mathbf{x̂_{min}}``.
662+
- `x̂max = fill(+Inf,nx̂)` : augmented state upper bounds ``\mathbf{x̂_{max}}``.
663+
- `ŵmin = fill(-Inf,nx̂)` : augmented process noise lower bounds ``\mathbf{ŵ_{min}}``.
664+
- `ŵmax = fill(+Inf,nx̂)` : augmented process noise upper bounds ``\mathbf{ŵ_{max}}``.
665+
- `v̂min = fill(-Inf,nym)` : sensor noise lower bounds ``\mathbf{v̂_{min}}``.
666+
- `v̂max = fill(+Inf,nym)` : sensor noise upper bounds ``\mathbf{v̂_{max}}``.
658667
- all the keyword arguments above but with a capital letter, e.g. `X̂max` or `V̂max` : for
659668
time-varying constraints (see Extended Help).
660669
@@ -967,7 +976,7 @@ time-varying ``\mathbf{P̄}`` weight (the estimation error covariance at arrival
967976
"""
968977
function initpred!(estim::MovingHorizonEstimator, model::LinModel)
969978
nx̂, nŵ, nym, Nk = estim.nx̂, estim.nx̂, estim.nym, estim.Nk[]
970-
nYm, nU, nD, nŴ = nym*Nk, model.nu*Nk, model.nd*Nk, nŵ*Nk
979+
nYm, nŴ = nym*Nk, nŵ*Nk
971980
nZ̃ = nx̂ + nŴ
972981
invQ̂_Nk, invR̂_Nk = @views estim.invQ̂_He[1:nŴ, 1:nŴ], estim.invR̂_He[1:nYm, 1:nYm]
973982
# --- update F and fx̄ vectors for MHE predictions ---
@@ -1068,10 +1077,12 @@ The method mutates `V̂` and `X̂` vector arguments. The vector `V̂` is the est
10681077
noises `V̂` from ``k-N_k+1`` to ``k``. The `X̂` vector is estimated states from ``k-N_k+2`` to
10691078
``k+1``.
10701079
"""
1071-
function predict!(V̂, X̂, estim::MovingHorizonEstimator, ::LinModel, Z̃)
1072-
nX̂, nYm = estim.nx̂*estim.Nk[], estim.nym*estim.Nk[]
1073-
V̂[1:nYm] = estim.*+ estim.F
1074-
X̂[1:nX̂] = estim.con.Ẽx̂*+ estim.con.Fx̂
1080+
function predict!(
1081+
V̂, X̂, estim::MovingHorizonEstimator, ::LinModel, Z̃::Vector{T}
1082+
) where {T<:Real}
1083+
nX̂, nYm, nZ̃ = estim.nx̂*estim.Nk[], estim.nym*estim.Nk[], estim.nx̂+estim.nx̂*estim.Nk[]
1084+
V̂[1:nYm] = @views estim.Ẽ[1:nYm, 1:nZ̃]*Z̃[1:nZ̃] + estim.F[1:nYm]
1085+
X̂[1:nX̂] = @views estim.con.Ẽx̂[1:nX̂, 1:nZ̃]*Z̃[1:nZ̃] + estim.con.Fx̂[1:nX̂]
10751086
return V̂, X̂
10761087
end
10771088

src/predictive_control.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ The matrices appear in the quadratic general form :
918918
```
919919
``\mathbf{H̃}`` is constant if the model and weights are linear and time invariant (LTI). The
920920
vector ``\mathbf{q̃}`` and scalar ``p`` need recalculation each control period ``k`` (see
921-
[`initpred!`](@ref) method). ``p`` does not impact the minima position. It is thus
921+
`initpred!`). ``p`` does not impact the minima position. It is thus
922922
useless at optimization but required to evaluate the minimal ``J`` value.
923923
"""
924924
function init_quadprog(::LinModel{NT}, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp) where {NT<:Real}

0 commit comments

Comments
 (0)