171
171
172
172
173
173
@doc raw """
174
- update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0=[])
174
+ update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0) -> x̂0next
175
175
176
176
Update `estim.x̂0` estimate with current inputs `u0`, measured outputs `y0m` and dist. `d0`.
177
177
@@ -181,7 +181,7 @@ The [`SteadyKalmanFilter`](@ref) updates it with the precomputed Kalman gain ``\
181
181
+ \m athbf{K̂}[\m athbf{y^m}(k) - \m athbf{Ĉ^m x̂}_{k-1}(k) - \m athbf{D̂_d^m d}(k)]
182
182
```
183
183
"""
184
- function update_estimate! (estim:: SteadyKalmanFilter , u0, y0m, d0= empty (estim . x̂0) )
184
+ function update_estimate! (estim:: SteadyKalmanFilter , u0, y0m, d0)
185
185
Â, B̂u, B̂d = estim. Â, estim. B̂u, estim. B̂d
186
186
x̂0, K̂ = estim. x̂0, estim. K̂
187
187
ŷ0m, x̂0next = similar (y0m), similar (x̂0)
@@ -195,8 +195,9 @@ function update_estimate!(estim::SteadyKalmanFilter, u0, y0m, d0=empty(estim.x̂
195
195
mul! (x̂0next, B̂u, u0, 1 , 1 )
196
196
mul! (x̂0next, B̂d, d0, 1 , 1 )
197
197
mul! (x̂0next, K̂, v̂, 1 , 1 )
198
+ x̂0next .+ = estim. f̂op .- estim. x̂op
198
199
estim. x̂0 .= x̂0next
199
- return nothing
200
+ return x̂0next
200
201
end
201
202
202
203
struct 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 {
320
321
end
321
322
322
323
@doc raw """
323
- update_estimate!(estim::KalmanFilter, u0, y0m, d0=[])
324
+ update_estimate!(estim::KalmanFilter, u0, y0m, d0) -> x̂0next
324
325
325
326
Update [`KalmanFilter`](@ref) state `estim.x̂0` and estimation error covariance `estim.P̂`.
326
327
@@ -344,7 +345,7 @@ control period ``k-1``. See [^2] for details.
344
345
[^2]: Boyd S., "Lecture 8 : The Kalman Filter" (Winter 2008-09) [course slides], *EE363:
345
346
Linear Dynamical Systems*, <https://web.stanford.edu/class/ee363/lectures/kf.pdf>.
346
347
"""
347
- function update_estimate! (estim:: KalmanFilter , u0, y0m, d0= empty (estim . x̂0) )
348
+ function update_estimate! (estim:: KalmanFilter , u0, y0m, d0)
348
349
Ĉm = @views estim. Ĉ[estim. i_ym, :]
349
350
return update_estimate_kf! (estim, u0, y0m, d0, estim. Â, Ĉm)
350
351
end
@@ -537,7 +538,7 @@ function init_ukf(::SimModel{NT}, nx̂, α, β, κ) where {NT<:Real}
537
538
end
538
539
539
540
@doc raw """
540
- update_estimate!(estim::UnscentedKalmanFilter, u0, y0m, d0=[])
541
+ update_estimate!(estim::UnscentedKalmanFilter, u0, y0m, d0) -> x̂0next
541
542
542
543
Update [`UnscentedKalmanFilter`](@ref) state `estim.x̂0` and covariance estimate `estim.P̂`.
543
544
@@ -576,9 +577,7 @@ noise, respectively.
576
577
Kalman, H∞, and Nonlinear Approaches", John Wiley & Sons, p. 433–459, <https://doi.org/10.1002/0470045345.ch14>,
577
578
ISBN9780470045343.
578
579
"""
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
582
581
x̂0, P̂, Q̂, R̂, K̂, M̂ = estim. x̂0, estim. P̂, estim. Q̂, estim. R̂, estim. K̂, estim. M̂
583
582
nym, nx̂ = estim. nym, estim. nx̂
584
583
γ, m̂, Ŝ = estim. γ, estim. m̂, estim. Ŝ
@@ -633,9 +632,10 @@ function update_estimate!(
633
632
X̄next .= X̂0next .- x̂0next
634
633
P̂next = P̂cor
635
634
P̂next. data .= X̄next * Ŝ * X̄next' .+ Q̂
635
+ x̂0next .+ = estim. f̂op .- estim. x̂op
636
636
estim. x̂0 .= x̂0next
637
637
estim. P̂ .= P̂next
638
- return nothing
638
+ return x̂0next
639
639
end
640
640
641
641
struct ExtendedKalmanFilter{NT<: Real , SM<: SimModel } <: StateEstimator{NT}
763
763
764
764
765
765
@doc raw """
766
- update_estimate!(estim::ExtendedKalmanFilter, u0, y0m, d0=[])
766
+ update_estimate!(estim::ExtendedKalmanFilter, u0, y0m, d0) -> x̂0next
767
767
768
768
Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂0` and covariance `estim.P̂`.
769
769
@@ -792,9 +792,7 @@ automatically computes the Jacobians:
792
792
```
793
793
The matrix ``\m athbf{Ĥ^m}`` is the rows of ``\m athbf{Ĥ}`` that are measured outputs.
794
794
"""
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
798
796
model = estim. model
799
797
nx̂, nu, ny = estim. nx̂, model. nu, model. ny
800
798
x̂0 = estim. x̂0
@@ -838,7 +836,7 @@ function validate_kfcov(nym, nx̂, Q̂, R̂, P̂_0=nothing)
838
836
end
839
837
840
838
"""
841
- update_estimate_kf!(estim::StateEstimator, u0, y0m, d0, Â, Ĉm)
839
+ update_estimate_kf!(estim::StateEstimator, u0, y0m, d0, Â, Ĉm) -> x̂0next
842
840
843
841
Update time-varying/extended Kalman Filter estimates with augmented `Â` and `Ĉm` matrices.
844
842
@@ -848,9 +846,7 @@ substitutes the augmented model matrices with its Jacobians (`Â = F̂` and `C
848
846
The implementation uses in-place operations and explicit factorization to reduce
849
847
allocations. See e.g. [`KalmanFilter`](@ref) docstring for the equations.
850
848
"""
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
854
850
Q̂, R̂, M̂, K̂ = estim. Q̂, estim. R̂, estim. M̂, estim. K̂
855
851
x̂0, P̂ = estim. x̂0, estim. P̂
856
852
nx̂, nu, ny = estim. nx̂, estim. model. nu, estim. model. ny
@@ -865,7 +861,8 @@ function update_estimate_kf!(
865
861
f̂! (x̂0next, û0, estim, estim. model, x̂0, u0, d0)
866
862
mul! (x̂0next, K̂, v̂, 1 , 1 )
867
863
P̂next = Hermitian (Â * (P̂ .- M̂ * Ĉm * P̂) * Â' .+ Q̂, :L )
864
+ x̂0next .+ = estim. f̂op .- estim. x̂op
868
865
estim. x̂0 .= x̂0next
869
866
estim. P̂ .= P̂next
870
- return nothing
867
+ return x̂0next
871
868
end
0 commit comments