@@ -841,7 +841,9 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
841
841
R̂:: Hermitian{NT, Matrix{NT}}
842
842
K̂:: Matrix{NT}
843
843
F̂_û:: Matrix{NT}
844
+ F̂ :: Matrix{NT}
844
845
Ĥ :: Matrix{NT}
846
+ Ĥm :: Matrix{NT}
845
847
direct:: Bool
846
848
corrected:: Vector{Bool}
847
849
buffer:: StateEstimatorBuffer{NT}
@@ -863,7 +865,8 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
863
865
R̂ = Hermitian (R̂, :L )
864
866
P̂ = copy (P̂_0)
865
867
K̂ = zeros (NT, nx̂, nym)
866
- F̂_û, Ĥ = zeros (NT, nx̂+ nu, nx̂), zeros (NT, ny, nx̂)
868
+ F̂_û, F̂ = zeros (NT, nx̂, nx̂+ nu), zeros (NT, nx̂, nx̂)
869
+ Ĥ, Ĥm = zeros (NT, ny, nx̂), zeros (NT, nym, nx̂)
867
870
corrected = [false ]
868
871
buffer = StateEstimatorBuffer {NT} (nu, nx̂, nym, ny, nd)
869
872
return new {NT, SM} (
@@ -874,7 +877,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
874
877
Â, B̂u, Ĉ, B̂d, D̂d, Ĉm, D̂dm,
875
878
P̂_0, Q̂, R̂,
876
879
K̂,
877
- F̂_û, Ĥ ,
880
+ F̂_û, F̂, Ĥ, Ĥm ,
878
881
direct, corrected,
879
882
buffer
880
883
)
@@ -965,8 +968,8 @@ function correct_estimate!(estim::ExtendedKalmanFilter, y0m, d0)
965
968
ŷ0 = estim. buffer. ŷ
966
969
ĥAD! = (ŷ0, x̂0) -> ĥ! (ŷ0, estim, model, x̂0, d0)
967
970
ForwardDiff. jacobian! (estim. Ĥ, ĥAD!, ŷ0, x̂0)
968
- Ĥm = @views estim. Ĥ[estim. i_ym, :]
969
- return correct_estimate_kf! (estim, y0m, d0, Ĥm)
971
+ estim . Ĥm . = @views estim. Ĥ[estim. i_ym, :]
972
+ return correct_estimate_kf! (estim, y0m, d0, estim . Ĥm)
970
973
end
971
974
972
975
@@ -1011,13 +1014,12 @@ The correction step is skipped if `estim.direct == true` since it's already done
1011
1014
function update_estimate! (estim:: ExtendedKalmanFilter{NT} , y0m, d0, u0) where NT<: Real
1012
1015
model, x̂0 = estim. model, estim. x̂0
1013
1016
nx̂, nu = estim. nx̂, model. nu
1014
- Ĥ = estim. Ĥ
1015
1017
if ! estim. direct
1016
1018
ŷ0 = estim. buffer. ŷ
1017
1019
ĥAD! = (ŷ0, x̂0) -> ĥ! (ŷ0, estim, model, x̂0, d0)
1018
- ForwardDiff. jacobian! (Ĥ, ĥAD!, ŷ0, x̂0)
1019
- Ĥm = @views Ĥ[estim. i_ym, :]
1020
- correct_estimate_kf! (estim, y0m, d0, Ĥm)
1020
+ ForwardDiff. jacobian! (estim . Ĥ, ĥAD!, ŷ0, x̂0)
1021
+ estim . Ĥm . = @views estim . Ĥ[estim. i_ym, :]
1022
+ correct_estimate_kf! (estim, y0m, d0, estim . Ĥm)
1021
1023
end
1022
1024
x̂0corr = estim. x̂0
1023
1025
# concatenate x̂0next and û0 vectors to allows û0 vector with dual numbers for AD:
@@ -1027,8 +1029,8 @@ function update_estimate!(estim::ExtendedKalmanFilter{NT}, y0m, d0, u0) where NT
1027
1029
x̂0nextû[1 : nx̂], x̂0nextû[nx̂+ 1 : end ], estim, model, x̂0corr, u0, d0
1028
1030
)
1029
1031
ForwardDiff. jacobian! (estim. F̂_û, f̂AD!, x̂0nextû, x̂0corr)
1030
- F̂ = @views estim. F̂_û[1 : estim. nx̂, :]
1031
- return predict_estimate_kf! (estim, u0, d0, F̂)
1032
+ estim . F̂ . = @views estim. F̂_û[1 : estim. nx̂, :]
1033
+ return predict_estimate_kf! (estim, u0, d0, estim . F̂)
1032
1034
end
1033
1035
1034
1036
" Set `estim.P̂` to `estim.P̂_0` for the time-varying Kalman Filters."
0 commit comments