171171
172172
173173@doc raw """
174- update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0=[])
174+ update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0) -> x̂0next
175175
176176Update `estim.x̂0` estimate with current inputs `u0`, measured outputs `y0m` and dist. `d0`.
177177
@@ -181,7 +181,7 @@ The [`SteadyKalmanFilter`](@ref) updates it with the precomputed Kalman gain ``\
181181 + \m athbf{K̂}[\m athbf{y^m}(k) - \m athbf{Ĉ^m x̂}_{k-1}(k) - \m athbf{D̂_d^m d}(k)]
182182```
183183"""
184- function update_estimate! (estim:: SteadyKalmanFilter , u0, y0m, d0= empty (estim . x̂0) )
184+ function update_estimate! (estim:: SteadyKalmanFilter , u0, y0m, d0)
185185 Â, B̂u, B̂d = estim. Â, estim. B̂u, estim. B̂d
186186 x̂0, K̂ = estim. x̂0, estim. K̂
187187 ŷ0m, x̂0next = similar (y0m), similar (x̂0)
@@ -195,8 +195,9 @@ function update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0=empty(estim.x̂
195195 mul! (x̂0next, B̂u, u0, 1 , 1 )
196196 mul! (x̂0next, B̂d, d0, 1 , 1 )
197197 mul! (x̂0next, K̂, v̂, 1 , 1 )
198+ x̂0next .+ = estim. f̂op .- estim. x̂op
198199 estim. x̂0 .= x̂0next
199- return nothing
200+ return x̂0next
200201end
201202
202203struct KalmanFilter{NT<: Real , SM<: LinModel } <: StateEstimator{NT}
@@ -320,7 +321,7 @@ function KalmanFilter(model::SM, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂) where {
320321end
321322
322323@doc raw """
323- update_estimate!(estim::KalmanFilter, u0, y0m, d0=[])
324+ update_estimate!(estim::KalmanFilter, u0, y0m, d0) -> x̂0next
324325
325326Update [`KalmanFilter`](@ref) state `estim.x̂0` and estimation error covariance `estim.P̂`.
326327
@@ -344,7 +345,7 @@ control period ``k-1``. See [^2] for details.
344345[^2]: Boyd S., "Lecture 8 : The Kalman Filter" (Winter 2008-09) [course slides], *EE363:
345346 Linear Dynamical Systems*, <https://web.stanford.edu/class/ee363/lectures/kf.pdf>.
346347"""
347- function update_estimate! (estim:: KalmanFilter , u0, y0m, d0= empty (estim . x̂0) )
348+ function update_estimate! (estim:: KalmanFilter , u0, y0m, d0)
348349 Ĉm = @views estim. Ĉ[estim. i_ym, :]
349350 return update_estimate_kf! (estim, u0, y0m, d0, estim. Â, Ĉm)
350351end
@@ -537,7 +538,7 @@ function init_ukf(::SimModel{NT}, nx̂, α, β, κ) where {NT<:Real}
537538end
538539
539540@doc raw """
540- update_estimate!(estim::UnscentedKalmanFilter, u0, y0m, d0=[])
541+ update_estimate!(estim::UnscentedKalmanFilter, u0, y0m, d0) -> x̂0next
541542
542543Update [`UnscentedKalmanFilter`](@ref) state `estim.x̂0` and covariance estimate `estim.P̂`.
543544
@@ -576,9 +577,7 @@ noise, respectively.
576577 Kalman, H∞, and Nonlinear Approaches", John Wiley & Sons, p. 433–459, <https://doi.org/10.1002/0470045345.ch14>,
577578 ISBN9780470045343.
578579"""
579- function update_estimate! (
580- estim:: UnscentedKalmanFilter{NT} , u0, y0m, d0= empty (estim. x̂0)
581- ) where NT<: Real
580+ function update_estimate! (estim:: UnscentedKalmanFilter{NT} , u0, y0m, d0) where NT<: Real
582581 x̂0, P̂, Q̂, R̂, K̂, M̂ = estim. x̂0, estim. P̂, estim. Q̂, estim. R̂, estim. K̂, estim. M̂
583582 nym, nx̂ = estim. nym, estim. nx̂
584583 γ, m̂, Ŝ = estim. γ, estim. m̂, estim. Ŝ
@@ -633,9 +632,10 @@ function update_estimate!(
633632 X̄next .= X̂0next .- x̂0next
634633 P̂next = P̂cor
635634 P̂next. data .= X̄next * Ŝ * X̄next' .+ Q̂
635+ x̂0next .+ = estim. f̂op .- estim. x̂op
636636 estim. x̂0 .= x̂0next
637637 estim. P̂ .= P̂next
638- return nothing
638+ return x̂0next
639639end
640640
641641struct ExtendedKalmanFilter{NT<: Real , SM<: SimModel } <: StateEstimator{NT}
763763
764764
765765@doc raw """
766- update_estimate!(estim::ExtendedKalmanFilter, u0, y0m, d0=[])
766+ update_estimate!(estim::ExtendedKalmanFilter, u0, y0m, d0) -> x̂0next
767767
768768Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂0` and covariance `estim.P̂`.
769769
@@ -792,9 +792,7 @@ automatically computes the Jacobians:
792792```
793793The matrix ``\m athbf{Ĥ^m}`` is the rows of ``\m athbf{Ĥ}`` that are measured outputs.
794794"""
795- function update_estimate! (
796- estim:: ExtendedKalmanFilter{NT} , u0, y0m, d0= empty (estim. x̂0)
797- ) where NT<: Real
795+ function update_estimate! (estim:: ExtendedKalmanFilter{NT} , u0, y0m, d0) where NT<: Real
798796 model = estim. model
799797 nx̂, nu, ny = estim. nx̂, model. nu, model. ny
800798 x̂0 = estim. x̂0
@@ -838,7 +836,7 @@ function validate_kfcov(nym, nx̂, Q̂, R̂, P̂_0=nothing)
838836end
839837
840838"""
841- update_estimate_kf!(estim::StateEstimator, u0, y0m, d0, Â, Ĉm)
839+ update_estimate_kf!(estim::StateEstimator, u0, y0m, d0, Â, Ĉm) -> x̂0next
842840
843841Update time-varying/extended Kalman Filter estimates with augmented `Â` and `Ĉm` matrices.
844842
@@ -848,9 +846,7 @@ substitutes the augmented model matrices with its Jacobians (`Â = F̂` and `C
848846The implementation uses in-place operations and explicit factorization to reduce
849847allocations. See e.g. [`KalmanFilter`](@ref) docstring for the equations.
850848"""
851- function update_estimate_kf! (
852- estim:: StateEstimator{NT} , u0, y0m, d0, Â, Ĉm
853- ) where NT<: Real
849+ function update_estimate_kf! (estim:: StateEstimator{NT} , u0, y0m, d0, Â, Ĉm) where NT<: Real
854850 Q̂, R̂, M̂, K̂ = estim. Q̂, estim. R̂, estim. M̂, estim. K̂
855851 x̂0, P̂ = estim. x̂0, estim. P̂
856852 nx̂, nu, ny = estim. nx̂, estim. model. nu, estim. model. ny
@@ -865,7 +861,8 @@ function update_estimate_kf!(
865861 f̂! (x̂0next, û0, estim, estim. model, x̂0, u0, d0)
866862 mul! (x̂0next, K̂, v̂, 1 , 1 )
867863 P̂next = Hermitian (Â * (P̂ .- M̂ * Ĉm * P̂) * Â' .+ Q̂, :L )
864+ x̂0next .+ = estim. f̂op .- estim. x̂op
868865 estim. x̂0 .= x̂0next
869866 estim. P̂ .= P̂next
870- return nothing
867+ return x̂0next
871868end
0 commit comments