@@ -420,13 +420,13 @@ function UnscentedKalmanFilter(
420420end
421421
422422@doc raw """
423- UnscentedKalmanFilter{M<:SimModel}(model, i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ)
423+ UnscentedKalmanFilter{M<:SimModel}(model::M , i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ)
424424
425425Construct the estimator from the augmented covariance matrices `P̂0`, `Q̂` and `R̂`.
426426
427427This syntax allows nonzero off-diagonal elements in ``\m athbf{P̂}_{-1}(0), \m athbf{Q̂, R̂}``.
428428"""
429- UnscentedKalmanFilter {M} (model:: SimModel , i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ) where {M}
429+ UnscentedKalmanFilter {M} (model:: M , i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ) where {M<: SimModel }
430430
431431
432432@doc raw """
@@ -584,8 +584,8 @@ identical to [`UnscentedKalmanFilter`](@ref). The Jacobians of the augmented mod
584584automatic differentiation.
585585
586586!!! warning
587- See Extended Help if you get an error like `MethodError: no method matching (::var"##")
588- (::Vector{ForwardDiff.Dual})`.
587+ See Extended Help if you get an error like:
588+ `MethodError: no method matching (::var"##") (::Vector{ForwardDiff.Dual})`.
589589
590590# Arguments
591591- `model::SimModel` : (deterministic) model for the estimations.
@@ -610,7 +610,6 @@ ExtendedKalmanFilter estimator with a sample time Ts = 5.0 s, NonLinModel and:
610610Automatic differentiation (AD) allows exact Jacobians. The [`NonLinModel`](@ref) `f` and `h`
611611functions must be compatible with this feature though. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
612612for common mistakes when writing these functions.
613- ```
614613"""
615614function ExtendedKalmanFilter (
616615 model:: M ;
@@ -629,22 +628,43 @@ function ExtendedKalmanFilter(
629628 return ExtendedKalmanFilter {M} (model, i_ym, nint_ym, P̂0, Q̂ , R̂)
630629end
631630
631+ @doc raw """
632+ ExtendedKalmanFilter{M<:SimModel}(model::M, i_ym, nint_ym, P̂0, Q̂, R̂)
633+
634+ Construct the estimator from the augmented covariance matrices `P̂0`, `Q̂` and `R̂`.
635+
636+ This syntax allows nonzero off-diagonal elements in ``\m athbf{P̂}_{-1}(0), \m athbf{Q̂, R̂}``.
637+ """
638+ ExtendedKalmanFilter {M} (model:: M , i_ym, nint_ym, P̂0 ,Q̂, R̂) where {M<: SimModel }
639+
632640@doc raw """
633641 update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=Float64[])
634642
635- Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂` and estimation error covariance `estim.P̂`.
643+ Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂` and covariance `estim.P̂`.
636644
637- The equations are identical to [`update_estimate!(::KalmanFilter)`](@ref) with the
638- substitutions ``\m athbf{Â = F̂}(k)`` and ``\m athbf{Ĉ^m = Ĥ^m}(k)``, and the Jacobians:
645+ The equations are similar to [`update_estimate!(::KalmanFilter)`](@ref) but with the
646+ substitutions ``\m athbf{Â = F̂}(k)`` and ``\m athbf{Ĉ^m = Ĥ^m}(k)``:
647+ ```math
648+ \b egin{aligned}
649+ \m athbf{M}(k) &= \m athbf{P̂}_{k-1}(k)\m athbf{Ĥ^m}'
650+ [\m athbf{Ĥ^m P̂}_{k-1}(k)\m athbf{Ĥ^m + R̂}]^{-1} \\
651+ \m athbf{K}(k) &= \m athbf{F̂ M(k)} \\
652+ \m athbf{ŷ^m}(k) &= \m athbf{ĥ^m}\B ig( \m athbf{x̂}_{k-1}(k), \m athbf{d}(k) \B ig) \\
653+ \m athbf{x̂}_{k}(k+1) &= \m athbf{f̂}\B ig( \m athbf{x̂}_{k-1}(k), \m athbf{u}(k), \m athbf{d}(k) \B ig)
654+ + \m athbf{K}(k)[\m athbf{y^m}(k) - \m athbf{ŷ^m}(k)] \\
655+ \m athbf{P̂}_{k}(k+1) &= \m athbf{F̂}[\m athbf{P̂}_{k-1}(k) -
656+ \m athbf{M}(k)\m athbf{Ĥ^m P̂}_{k-1}(k)]\m athbf{F̂}' + \m athbf{Q̂}
657+ \e nd{aligned}
658+ ```
659+ [`ForwardDiff.jacobian`](https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian)
660+ automatically computes the Jacobians:
639661```math
640662\b egin{aligned}
641663 \m athbf{F̂}(k) &= \l eft. \f rac{∂\m athbf{f̂}(\m athbf{x̂}, \m athbf{u}, \m athbf{d})}{∂\m athbf{x̂}} \r ight|_{\m athbf{x̂ = x̂}_{k-1}(k),\, \m athbf{u = u}(k),\, \m athbf{d = d}(k)} \\
642664 \m athbf{Ĥ}(k) &= \l eft. \f rac{∂\m athbf{ĥ}(\m athbf{x̂}, \m athbf{d})}{∂\m athbf{x̂}} \r ight|_{\m athbf{x = x̂}_{k-1}(k),\, \m athbf{d = d}(k)}
643665\e nd{aligned}
644666```
645- The matrix ``\m athbf{Ĥ^m}(k)`` is the rows of ``\m athbf{Ĥ}(k)`` that are measured outputs.
646- The function [`ForwardDiff.jacobian`](https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian)
647- computes ``\m athbf{F̂}(k)`` and ``\m athbf{Ĥ}(k)``.
667+ The matrix ``\m athbf{Ĥ^m}`` is the rows of ``\m athbf{Ĥ}`` that are measured outputs.
648668"""
649669function update_estimate! (estim:: ExtendedKalmanFilter , u, ym, d= Float64[])
650670 x̂, P̂, Q̂, R̂ = estim. x̂, estim. P̂, estim. Q̂, estim. R̂
@@ -659,28 +679,14 @@ function update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=Float64[])
659679 return x̂, P̂
660680end
661681
662-
663- """
664- initstate!(
665- estim::Union{KalmanFilter, UnscentedKalmanFilter, ExtendedKalmanFilter},
666- u,
667- ym,
668- d=Float64[]
669- )
670-
671- Initialize covariance `estim.P̂` and invoke [`initstate!(::StateEstimator)`](@ref).
672- """
673- function initstate! (
674- estim:: Union{KalmanFilter, UnscentedKalmanFilter, ExtendedKalmanFilter} ,
675- u,
676- ym,
677- d= Float64[]
678- )
679- estim. P̂. data[:] = estim. P̂0 # .data is necessary for Hermitian matrices
680- invoke (initstate!, Tuple{StateEstimator, Any, Any, Any}, estim, u, ym, d)
682+ " Initialize the covariance estimate `P̂` for the time-varying Kalman Filters"
683+ function initstate_cov! (
684+ estim:: Union{KalmanFilter, UnscentedKalmanFilter, ExtendedKalmanFilter}
685+ )
686+ estim. P̂. data[:] = estim. P̂0
687+ return nothing
681688end
682689
683-
684690"""
685691 validate_kfcov(nym, nx̂, Q̂, R̂, P̂0=nothing)
686692
0 commit comments