Skip to content

Commit bd23b20

Browse files
committed
doctest corrections
1 parent 65fdce2 commit bd23b20

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/estimator/kalman.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ unmeasured ones, for ``\mathbf{Ĉ^u, D̂_d^u}``).
105105
```jldoctest
106106
julia> model = LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 0.5);
107107
108-
julia> estim = SteadyKalmanFilter(model, i_ym=[2], σR=[1], σQ_int=[0.01])
108+
julia> estim = SteadyKalmanFilter(model, i_ym=[2], σR=[1], σQint_ym=[0.01])
109109
SteadyKalmanFilter estimator with a sample time Ts = 0.5 s, LinModel and:
110110
1 manipulated inputs u
111111
3 states x̂
@@ -115,19 +115,20 @@ SteadyKalmanFilter estimator with a sample time Ts = 0.5 s, LinModel and:
115115
```
116116
117117
# Extended Help
118-
The model augmentation with `nint_u` vector adds integrators at model manipulated inputs,
118+
The model augmentation with `nint_u` vector adds integrators at model manipulated inputs,
119119
and `nint_ym`, at measured outputs. They create the integral action when the estimator is
120-
used in a controller as state feedback. The method [`default_nint`](@ref) computes the
121-
default value of `nint_ym`. It can also be tweaked by following these rules on each measured output:
120+
used in a controller as state feedback. By default, the method [`default_nint`](@ref) adds
121+
one integrator per measured output if feasible. The argument `nint_ym` can also be tweaked
122+
by following these rules on each measured output:
122123
123124
- Use 0 integrator if the model output is already integrating (else it will be unobservable)
124125
- Use 1 integrator if the disturbances on the output are typically "step-like"
125126
- Use 2 integrators if the disturbances on the output are typically "ramp-like"
126127
127-
The function [`init_integrators`](@ref) builds the stochastic model from `nint_ym`.
128+
The function [`init_estimstoch`](@ref) builds the stochastic model for estimation.
128129
129130
!!! tip
130-
Increasing `σQ_int` values increases the integral action "gain".
131+
Increasing `σQint_u` and `σQint_ym` values increases the integral action "gain".
131132
132133
The constructor pre-compute the steady-state Kalman gain `K` with the [`kalman`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/synthesis/#ControlSystemsBase.kalman-Tuple{Any,%20Any,%20Any,%20Any,%20Any,%20Vararg{Any}})
133134
function. It can sometimes fail, for example when `model` matrices are ill-conditioned. In
@@ -252,7 +253,7 @@ value with ``\mathbf{P̂}_{-1}(0) =
252253
```jldoctest
253254
julia> model = LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 0.5);
254255
255-
julia> estim = KalmanFilter(model, i_ym=[2], σR=[1], σP0=[100, 100], σQ_int=[0.01])
256+
julia> estim = KalmanFilter(model, i_ym=[2], σR=[1], σP0=[100, 100], σQint_ym=[0.01])
256257
KalmanFilter estimator with a sample time Ts = 0.5 s, LinModel and:
257258
1 manipulated inputs u
258259
3 states x̂
@@ -400,13 +401,14 @@ unmeasured ones, for ``\mathbf{ĥ^u}``).
400401
```jldoctest
401402
julia> model = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10.0, 1, 1, 1);
402403
403-
julia> estim = UnscentedKalmanFilter(model, σR=[1], nint_ym=[2], σP0_int=[1, 1])
404+
julia> estim = UnscentedKalmanFilter(model, σR=[1], nint_ym=[2], σP0int_ym=[1, 1])
404405
UnscentedKalmanFilter estimator with a sample time Ts = 10.0 s, NonLinModel and:
405406
1 manipulated inputs u
406407
3 states x̂
407408
1 measured outputs ym
408409
0 unmeasured outputs yu
409410
0 measured disturbances d
411+
```
410412
411413
# Extended Help
412414
The Extended Help of [`SteadyKalmanFilter`](@ref) details the augmentation with `nint_ym`
@@ -439,13 +441,13 @@ function UnscentedKalmanFilter(
439441
end
440442

441443
@doc raw"""
442-
UnscentedKalmanFilter{M<:SimModel}(model::M, i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ)
444+
UnscentedKalmanFilter{M<:SimModel}(model::M, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂, α, β, κ)
443445
444446
Construct the estimator from the augmented covariance matrices `P̂0`, `Q̂` and `R̂`.
445447
446448
This syntax allows nonzero off-diagonal elements in ``\mathbf{P̂}_{-1}(0), \mathbf{Q̂, R̂}``.
447449
"""
448-
UnscentedKalmanFilter{M}(model::M, i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ) where {M<:SimModel}
450+
UnscentedKalmanFilter{M}(model::M, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂, α, β, κ) where {M<:SimModel}
449451

450452

451453
@doc raw"""
@@ -616,7 +618,7 @@ automatic differentiation.
616618
```jldoctest
617619
julia> model = NonLinModel((x,u,_)->0.2x+u, (x,_)->-3x, 5.0, 1, 1, 1);
618620
619-
julia> estim = ExtendedKalmanFilter(model, σQ=[2], σQ_int=[2], σP0=[0.1], σP0_int=[0.1])
621+
julia> estim = ExtendedKalmanFilter(model, σQ=[2], σQint_ym=[2], σP0=[0.1], σP0int_ym=[0.1])
620622
ExtendedKalmanFilter estimator with a sample time Ts = 5.0 s, NonLinModel and:
621623
1 manipulated inputs u
622624
2 states x̂
@@ -626,7 +628,6 @@ ExtendedKalmanFilter estimator with a sample time Ts = 5.0 s, NonLinModel and:
626628
```
627629
628630
# Extended Help
629-
630631
Automatic differentiation (AD) allows exact Jacobians. The [`NonLinModel`](@ref) `f` and `h`
631632
functions must be compatible with this feature though. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
632633
for common mistakes when writing these functions.
@@ -652,13 +653,13 @@ function ExtendedKalmanFilter(
652653
end
653654

654655
@doc raw"""
655-
ExtendedKalmanFilter{M<:SimModel}(model::M, i_ym, nint_ym, P̂0, Q̂, R̂)
656+
ExtendedKalmanFilter{M<:SimModel}(model::M, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂)
656657
657658
Construct the estimator from the augmented covariance matrices `P̂0`, `Q̂` and `R̂`.
658659
659660
This syntax allows nonzero off-diagonal elements in ``\mathbf{P̂}_{-1}(0), \mathbf{Q̂, R̂}``.
660661
"""
661-
ExtendedKalmanFilter{M}(model::M, i_ym, nint_ym, P̂0 ,Q̂, R̂) where {M<:SimModel}
662+
ExtendedKalmanFilter{M}(model::M, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂) where {M<:SimModel}
662663

663664
@doc raw"""
664665
update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=Float64[])

src/state_estim.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ function remove_op!(estim::StateEstimator, u, d, ym)
7070
end
7171

7272
"""
73-
init_estimstoch(model, i_ym, nint_u, nint_ym)
73+
init_estimstoch(model, i_ym, nint_u, nint_ym) -> As, Cs_u, Cs_y, nxs, nint_u, nint_ym
7474
7575
Init stochastic model matrices from integrator specifications for state estimation.
76+
77+
TBW.
78+
79+
The function [`init_integrators`](@ref) builds the state-space matrice of the unmeasured
80+
disturbance models.
7681
"""
77-
function init_estimstoch(model, i_ym, nint_u, nint_ym)
82+
function init_estimstoch(model, i_ym, nint_u::IntVectorOrInt, nint_ym::IntVectorOrInt)
7883
nu, ny, nym = model.nu, model.ny, length(i_ym)
7984
As_u , Cs_u , nint_u = init_integrators(nint_u , nu , "u")
8085
As_ym, Cs_ym, nint_ym = init_integrators(nint_ym, nym, "ym")
@@ -113,7 +118,7 @@ function stoch_ym2y(model::SimModel, i_ym, Asm, Bsm, Csm, Dsm)
113118
end
114119

115120
@doc raw"""
116-
init_integrators(nint::Vector{Int}, nys, varname::String) -> As, Cs, nint
121+
init_integrators(nint, nys, varname::String) -> As, Cs, nint
117122
118123
Calc state-space matrices `As, Cs` (stochastic part) from integrator specifications `nint`.
119124

test/test_state_estim.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sys = [ tf(1.90,[18.0,1]) tf(1.90,[18.0,1]) tf(1.90,[18.0,1]);
2828
@test skalmanfilter4.nxs == 4
2929
@test skalmanfilter4.nx̂ == 6
3030

31-
skalmanfilter5 = SteadyKalmanFilter(linmodel2, σQ=[1,2,3,4], σQ_int=[5, 6], σR=[7, 8])
31+
skalmanfilter5 = SteadyKalmanFilter(linmodel2, σQ=[1,2,3,4], σQint_ym=[5, 6], σR=[7, 8])
3232
@test skalmanfilter5. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
3333
@test skalmanfilter5. Hermitian(diagm(Float64[49, 64]))
3434

@@ -86,7 +86,7 @@ end
8686
@test kalmanfilter4.nxs == 4
8787
@test kalmanfilter4.nx̂ == 6
8888

89-
kalmanfilter5 = KalmanFilter(linmodel2, σQ=[1,2,3,4], σQ_int=[5, 6], σR=[7, 8])
89+
kalmanfilter5 = KalmanFilter(linmodel2, σQ=[1,2,3,4], σQint_ym=[5, 6], σR=[7, 8])
9090
@test kalmanfilter5. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
9191
@test kalmanfilter5. Hermitian(diagm(Float64[49, 64]))
9292

@@ -258,15 +258,15 @@ end
258258
@test ukf3.nxs == 1
259259
@test ukf3.nx̂ == 5
260260

261-
ukf4 = UnscentedKalmanFilter(nonlinmodel, σQ=[1,2,3,4], σQ_int=[5, 6], σR=[7, 8])
261+
ukf4 = UnscentedKalmanFilter(nonlinmodel, σQ=[1,2,3,4], σQint_ym=[5, 6], σR=[7, 8])
262262
@test ukf4. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
263263
@test ukf4. Hermitian(diagm(Float64[49, 64]))
264264

265265
ukf5 = UnscentedKalmanFilter(nonlinmodel, nint_ym=[2,2])
266266
@test ukf5.nxs == 4
267267
@test ukf5.nx̂ == 8
268268

269-
ukf6 = UnscentedKalmanFilter(nonlinmodel, σP0=[1,2,3,4], σP0_int=[5,6])
269+
ukf6 = UnscentedKalmanFilter(nonlinmodel, σP0=[1,2,3,4], σP0int_ym=[5,6])
270270
@test ukf6.P̂0 Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
271271
@test ukf6. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
272272
@test ukf6.P̂0 !== ukf6.
@@ -316,15 +316,15 @@ end
316316
@test ekf3.nxs == 1
317317
@test ekf3.nx̂ == 5
318318

319-
ekf4 = ExtendedKalmanFilter(nonlinmodel, σQ=[1,2,3,4], σQ_int=[5, 6], σR=[7, 8])
319+
ekf4 = ExtendedKalmanFilter(nonlinmodel, σQ=[1,2,3,4], σQint_ym=[5, 6], σR=[7, 8])
320320
@test ekf4. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
321321
@test ekf4. Hermitian(diagm(Float64[49, 64]))
322322

323323
ekf5 = ExtendedKalmanFilter(nonlinmodel, nint_ym=[2,2])
324324
@test ekf5.nxs == 4
325325
@test ekf5.nx̂ == 8
326326

327-
ekf6 = ExtendedKalmanFilter(nonlinmodel, σP0=[1,2,3,4], σP0_int=[5,6])
327+
ekf6 = ExtendedKalmanFilter(nonlinmodel, σP0=[1,2,3,4], σP0int_ym=[5,6])
328328
@test ekf6.P̂0 Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
329329
@test ekf6. Hermitian(diagm(Float64[1, 4, 9 ,16, 25, 36]))
330330
@test ekf6.P̂0 !== ekf6.

0 commit comments

Comments
 (0)