Skip to content

Commit 9e50689

Browse files
authored
Merge pull request #235 from JuliaControl/doc_model_aug
doc: clarifying model augmentation for `NonLinMPC` in `f̂!` docstring
2 parents 9b87de8 + ecc8f64 commit 9e50689

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

docs/src/internals/state_estim.md

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

7-
## Augmented Model
8-
9-
```@docs
10-
ModelPredictiveControl.f̂!
11-
ModelPredictiveControl.ĥ!
12-
```
13-
147
## Estimator Construction
158

169
```@docs
@@ -28,6 +21,13 @@ ModelPredictiveControl.init_matconstraint_mhe
2821
ModelPredictiveControl.get_optim_functions(::MovingHorizonEstimator, ::ModelPredictiveControl.GenericModel)
2922
```
3023

24+
## Augmented Model
25+
26+
```@docs
27+
ModelPredictiveControl.f̂!
28+
ModelPredictiveControl.ĥ!
29+
```
30+
3131
## Update Quadratic Optimization
3232

3333
```@docs

src/estimator/construct.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ end
236236
237237
Augment [`LinModel`](@ref) state-space matrices with stochastic ones `As`, `Cs_u`, `Cs_y`.
238238
239-
If ``\mathbf{x_0}`` are `model.x0` states, and ``\mathbf{x_s}``, the states defined at
240-
[`init_estimstoch`](@ref), we define an augmented state vector ``\mathbf{} =
239+
If ``\mathbf{x_0}`` is `model.x0` state, and ``\mathbf{x_s}``, the states defined at
240+
[`init_estimstoch`](@ref), we define an augmented state vector ``\mathbf{x̂_0} =
241241
[ \begin{smallmatrix} \mathbf{x_0} \\ \mathbf{x_s} \end{smallmatrix} ]``. The method
242242
returns the augmented matrices `Â`, `B̂u`, `Ĉ`, `B̂d` and `D̂d`:
243243
```math
@@ -253,9 +253,9 @@ See Extended Help for a detailed definition of the augmented matrices and vector
253253
254254
# Extended Help
255255
!!! details "Extended Help"
256-
Using the `As`, `Cs_u` and `Cs_y` matrices of the stochastic model provided in argument
257-
and the `model.A`, `model.Bu`, `model.Bd`, `model.C`, `model.Dd` matrices, the
258-
state-space matrices of the augmented model are defined as follows:
256+
Using the `As`, `Cs_u` and `Cs_y` matrices of the stochastic model constructed in
257+
[`init_estimstoch`](@ref)), and `model.A`, `model.Bu`, `model.Bd`, `model.C`, `model.Dd`
258+
matrices, the state-space matrices of the augmented model are defined as follows:
259259
```math
260260
\begin{aligned}
261261
\mathbf{Â} &= \begin{bmatrix}

src/estimator/execute.jl

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,44 @@ end
1818
1919
Mutating state function ``\mathbf{f̂}`` of the augmented model.
2020
21-
By introducing an augmented state vector ``\mathbf{x̂_0}`` like in [`augment_model`](@ref), the
22-
function returns the next state of the augmented model, defined as:
21+
By introducing an augmented state vector ``\mathbf{x̂_0}`` like in [`augment_model`](@ref),
22+
the function returns the next state of the augmented model, defined as:
2323
```math
2424
\begin{aligned}
2525
\mathbf{x̂_0}(k+1) &= \mathbf{f̂}\Big(\mathbf{x̂_0}(k), \mathbf{u_0}(k), \mathbf{d_0}(k)\Big) \\
2626
\mathbf{ŷ_0}(k) &= \mathbf{ĥ}\Big(\mathbf{x̂_0}(k), \mathbf{d_0}(k)\Big)
2727
\end{aligned}
2828
```
2929
where ``\mathbf{x̂_0}(k+1)`` is stored in `x̂0next` argument. The method mutates `x̂0next`,
30-
`û0` and `k0` in place. The argument `û0` is the input vector of the augmented model,
31-
computed by ``\mathbf{û_0 = u_0 + ŷ_{s_u}}``. The argument `k0` is used to store the
32-
intermediate stage values of `model.solver` (when applicable). The model parameter vector
33-
`model.p` is not included in the function signature for conciseness.
30+
`û0` and `k0` in place. The argument `û0` stores the disturbed input of the augmented model
31+
``\mathbf{û_0}``, and `k0`, the intermediate stage values of `model.solver`, when applicable.
32+
The model parameter `model.p` is not included in the function signature for conciseness. See
33+
Extended Help for details on ``\mathbf{û_0, f̂}`` and ``\mathbf{ĥ}`` implementations.
34+
35+
# Extended Help
36+
!!! details "Extended Help"
37+
Knowing that the augmented state vector is defined as
38+
``\mathbf{x̂_0} = [ \begin{smallmatrix} \mathbf{x_0} \\ \mathbf{x_s} \end{smallmatrix} ]``,
39+
the augmented model functions are:
40+
```math
41+
\begin{aligned}
42+
\mathbf{f̂}\Big(\mathbf{x̂_0}(k), \mathbf{u_0}(k), \mathbf{d_0}(k)\Big) &= \begin{bmatrix}
43+
\mathbf{f}\Big(\mathbf{x_0}(k), \mathbf{û_0}(k), \mathbf{d_0}(k), \mathbf{p}\Big) \\
44+
\mathbf{A_s} \mathbf{x_s}(k) \end{bmatrix} \\
45+
\mathbf{ĥ}\Big(\mathbf{x̂_0}(k), \mathbf{d_0}(k)\Big) &=
46+
\mathbf{h}\Big(\mathbf{x_0}(k), \mathbf{d_0}(k), \mathbf{p}\Big) + \mathbf{y_{s_y}}(k)
47+
\end{aligned}
48+
```
49+
in which:
50+
```math
51+
\begin{aligned}
52+
\mathbf{û_0}(k) &= \mathbf{u_0}(k) + \mathbf{y_{s_u}}(k) \\
53+
\mathbf{y_{s_u}}(k) &= \mathbf{C_{s_u} x_s}(k) \\
54+
\mathbf{y_{s_y}}(k) &= \mathbf{C_{s_y} x_s}(k)
55+
\end{aligned}
56+
```
57+
The ``\mathbf{f}`` and ``\mathbf{h}`` functions above are in fact the [`f!`](@ref) and
58+
[`h!`](@ref) methods, respectively.
3459
"""
3560
function f̂!(x̂0next, û0, k0, estim::StateEstimator, model::SimModel, x̂0, u0, d0)
3661
return f̂!(x̂0next, û0, k0, model, estim.As, estim.Cs_u, x̂0, u0, d0)

src/estimator/kalman.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ augmented process model:
11251125
\end{aligned}
11261126
```
11271127
The matrix ``\mathbf{Ĥ^m}`` is the rows of ``\mathbf{Ĥ}`` that are measured outputs. The
1128-
Jacobians are computed with [`ForwardDiff`](@extref ForwardDiff) bu default. The correction
1128+
Jacobians are computed with [`ForwardDiff`](@extref ForwardDiff) by default. The correction
11291129
and prediction step equations are provided below. The correction step is skipped if
11301130
`estim.direct == true` since it's already done by the user.
11311131

0 commit comments

Comments
 (0)