Skip to content

Commit 2c1c854

Browse files
committed
debug initstate! when nym ≠ ny
1 parent 86e2c40 commit 2c1c854

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

docs/src/internals/state_estim.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ ModelPredictiveControl.ĥ
2727
ModelPredictiveControl.remove_op!
2828
```
2929

30-
## Init Estimate
30+
## Update Estimate
3131

3232
!!! info
3333
All these methods assume that the operating points are already removed in `u`, `ym`
3434
and `d` arguments. Strickly speaking, the arguments should be called `u0`, `ym0` and
3535
`d0`, following [`setop!`](@ref) notation. The `0` is dropped to simplify the notation.
3636

3737
```@docs
38-
ModelPredictiveControl.init_estimate!
38+
ModelPredictiveControl.update_estimate!
3939
```
4040

41-
## Update Estimate
41+
## Init Estimate
4242

4343
!!! info
4444
Same as above: the arguments should be called `u0`, `ym0` and `d0`, strickly speaking.
4545

4646
```@docs
47-
ModelPredictiveControl.update_estimate!
47+
ModelPredictiveControl.init_estimate!
4848
```

src/model/linmodel.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Construct the model from the discrete state-space matrices `A, Bu, C, Bd, Dd` di
189189
190190
This syntax do not modify the state-space representation provided in argument ([`minreal`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/constructors/#ControlSystemsBase.minreal)
191191
is not called). Care must be taken to ensure that the model is controllable and observable.
192+
192193
"""
193194
LinModel(A, Bu, C, Bd, Dd, Ts, nu, nx, ny, nd)
194195

src/state_estim.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,38 +321,37 @@ function initstate!(estim::StateEstimator, u, ym, d=Float64[])
321321
return estim.
322322
end
323323

324+
"By default, do nothing at the end of `initstate!` (used to init the covariance estimate)."
325+
initstate_post!(::StateEstimator) = nothing
326+
324327
@doc raw"""
325328
init_estimate!(estim::StateEstimator, model::LinModel, u, ym, d)
326329
327330
Init `estim.x̂` estimate with the steady-state solution if `model` is a [`LinModel`](@ref).
328331
329332
Using `u`, `ym` and `d` arguments, the steady-state problem combined to the equality
330-
constraint ``\mathbf{ŷ^m} = \mathbf{y^m}`` engenders the following system to solve :
333+
constraint ``\mathbf{ŷ^m} = \mathbf{y^m}`` engenders the following system to solve:
331334
```math
332335
\begin{bmatrix}
333336
\mathbf{I} - \mathbf{Â} \\
334-
\mathbf{Ĉ}
337+
\mathbf{Ĉ^m}
335338
\end{bmatrix} \mathbf{x̂} =
336339
\begin{bmatrix}
337340
\mathbf{B̂_u u} + \mathbf{B̂_d d} \\
338-
\mathbf{y} - \mathbf{D̂_d d}
341+
\mathbf{y^m} - \mathbf{D̂_d^m d}
339342
\end{bmatrix}
340343
```
341-
in which ``\mathbf{y}`` comprises the measured ``\mathbf{y^m}`` and unmeasured
342-
``\mathbf{y^u = 0}`` outputs.
344+
in which ``\mathbf{Ĉ^m, D̂_d^m}`` are the rows of `estim.Ĉ, estim.D̂d` that correspond to
345+
measured outputs ``\mathbf{y^m}``.
343346
"""
344-
function init_estimate!(estim::StateEstimator, model::LinModel, u, ym, d)
347+
function init_estimate!(estim::StateEstimator, ::LinModel, u, ym, d)
345348
Â, B̂u, Ĉ, B̂d, D̂d = estim.Â, estim.B̂u, estim.Ĉ, estim.B̂d, estim.D̂d
346-
y = zeros(model.ny)
347-
y[estim.i_ym] = ym
348-
estim.x̂[:] = [(I - Â); Ĉ]\[B̂u*u + B̂d*d; y - D̂d*d]
349+
Ĉm, D̂dm = Ĉ[estim.i_ym, :], D̂d[estim.i_ym, :] # measured outputs ym only
350+
estim.x̂[:] = [(I - Â); Ĉm]\[B̂u*u + B̂d*d; ym - D̂dm*d]
349351
end
350352
"Left `estim.x̂` estimate unchanged if `model` is not a [`LinModel`](@ref)."
351353
init_estimate!(::StateEstimator, ::SimModel, _ , _ , _ ) = nothing
352354

353-
"By default, do nothing at the end of `initstate!` (used to init the covariance estimate)."
354-
initstate_post!(::StateEstimator) = nothing
355-
356355
@doc raw"""
357356
evaloutput(estim::StateEstimator, d=Float64[]) -> ŷ
358357

0 commit comments

Comments
 (0)