@@ -23,6 +23,7 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
2323 R̂:: Hermitian{NT, Matrix{NT}}
2424 K̂:: Matrix{NT}
2525 direct:: Bool
26+ corrected:: Vector{Bool}
2627 buffer:: StateEstimatorBuffer{NT}
2728 function SteadyKalmanFilter {NT, SM} (
2829 model:: SM , i_ym, nint_u, nint_ym, Q̂, R̂; direct= true
@@ -51,6 +52,7 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
5152 lastu0 = zeros (NT, nu)
5253 x̂0 = [zeros (NT, model. nx); zeros (NT, nxs)]
5354 Q̂, R̂ = Hermitian (Q̂, :L ), Hermitian (R̂, :L )
55+ corrected = [false ]
5456 buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd)
5557 return new {NT, SM} (
5658 model,
@@ -60,7 +62,7 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
6062 Â, B̂u, Ĉ, B̂d, D̂d,
6163 Q̂, R̂,
6264 K̂,
63- direct,
65+ direct, corrected,
6466 buffer
6567 )
6668 end
@@ -271,6 +273,7 @@ struct KalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
271273 K̂:: Matrix{NT}
272274 M̂:: Matrix{NT}
273275 direct:: Bool
276+ corrected:: Vector{Bool}
274277 buffer:: StateEstimatorBuffer{NT}
275278 function KalmanFilter {NT, SM} (
276279 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct= true
@@ -288,6 +291,7 @@ struct KalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
288291 P̂_0 = Hermitian (P̂_0, :L )
289292 P̂ = copy (P̂_0)
290293 K̂, M̂ = zeros (NT, nx̂, nym), zeros (NT, nx̂, nym)
294+ corrected = [false ]
291295 buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd)
292296 return new {NT, SM} (
293297 model,
@@ -297,7 +301,7 @@ struct KalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
297301 Â, B̂u, Ĉ, B̂d, D̂d,
298302 P̂_0, Q̂, R̂,
299303 K̂, M̂,
300- direct,
304+ direct, corrected,
301305 buffer
302306 )
303307 end
@@ -459,6 +463,7 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
459463 m̂:: Vector{NT}
460464 Ŝ:: Diagonal{NT, Vector{NT}}
461465 direct:: Bool
466+ corrected:: Vector{Bool}
462467 buffer:: StateEstimatorBuffer{NT}
463468 function UnscentedKalmanFilter {NT, SM} (
464469 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂, α, β, κ; direct= true
@@ -480,6 +485,7 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
480485 M̂ = Hermitian (zeros (NT, nym, nym), :L )
481486 X̂0, Ŷ0m = zeros (NT, nx̂, nσ), zeros (NT, nym, nσ)
482487 sqrtP̂ = LowerTriangular (zeros (NT, nx̂, nx̂))
488+ corrected = [false ]
483489 buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd)
484490 return new {NT, SM} (
485491 model,
@@ -490,7 +496,7 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
490496 P̂_0, Q̂, R̂,
491497 K̂, M̂, X̂0, Ŷ0m, sqrtP̂,
492498 nσ, γ, m̂, Ŝ,
493- direct,
499+ direct, corrected,
494500 buffer
495501 )
496502 end
@@ -777,6 +783,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
777783 F̂_û:: Matrix{NT}
778784 Ĥ :: Matrix{NT}
779785 direct:: Bool
786+ corrected:: Vector{Bool}
780787 buffer:: StateEstimatorBuffer{NT}
781788 function ExtendedKalmanFilter {NT, SM} (
782789 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct= true
@@ -796,6 +803,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
796803 P̂ = copy (P̂_0)
797804 K̂, M̂ = zeros (NT, nx̂, nym), zeros (NT, nx̂, nym)
798805 F̂_û, Ĥ = zeros (NT, nx̂+ nu, nx̂), zeros (NT, ny, nx̂)
806+ corrected = [false ]
799807 buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd)
800808 return new {NT, SM} (
801809 model,
@@ -806,7 +814,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
806814 P̂_0, Q̂, R̂,
807815 K̂, M̂,
808816 F̂_û, Ĥ,
809- direct,
817+ direct, corrected,
810818 buffer
811819 )
812820 end
@@ -1007,7 +1015,7 @@ end
10071015"""
10081016 update_estimate_kf!(estim::StateEstimator, y0m, d0, u0, Ĉm, Â)
10091017
1010- Update time-varying/extended Kalman Filter estimates with augmented `Â ` and `Ĉm ` matrices.
1018+ Update time-varying/extended Kalman Filter estimates with augmented `Ĉm ` and `Â ` matrices.
10111019
10121020Allows code reuse for [`KalmanFilter`](@ref), [`ExtendedKalmanFilterKalmanFilter`](@ref).
10131021They update the state `x̂` and covariance `P̂` with the same equations. The extended filter
0 commit comments