@@ -22,6 +22,7 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
2222 Q̂:: Hermitian{NT, Matrix{NT}}
2323 R̂:: Hermitian{NT, Matrix{NT}}
2424 K̂:: Matrix{NT}
25+ buffer:: StateEstimatorBuffer{NT}
2526 function SteadyKalmanFilter {NT, SM} (
2627 model:: SM , i_ym, nint_u, nint_ym, Q̂, R̂
2728 ) where {NT<: Real , SM<: LinModel }
@@ -48,14 +49,16 @@ struct SteadyKalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
4849 lastu0 = zeros (NT, model. nu)
4950 x̂0 = [zeros (NT, model. nx); zeros (NT, nxs)]
5051 Q̂, R̂ = Hermitian (Q̂, :L ), Hermitian (R̂, :L )
52+ buffer = StateEstimatorBuffer {NT} (nx̂, nym)
5153 return new {NT, SM} (
5254 model,
5355 lastu0, x̂op, f̂op, x̂0,
5456 i_ym, nx̂, nym, nyu, nxs,
5557 As, Cs_u, Cs_y, nint_u, nint_ym,
5658 Â, B̂u, Ĉ, B̂d, D̂d,
5759 Q̂, R̂,
58- K̂
60+ K̂,
61+ buffer
5962 )
6063 end
6164end
@@ -234,6 +237,7 @@ struct KalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
234237 R̂:: Hermitian{NT, Matrix{NT}}
235238 K̂:: Matrix{NT}
236239 M̂:: Matrix{NT}
240+ buffer:: StateEstimatorBuffer{NT}
237241 function KalmanFilter {NT, SM} (
238242 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂
239243 ) where {NT<: Real , SM<: LinModel }
@@ -249,14 +253,16 @@ struct KalmanFilter{NT<:Real, SM<:LinModel} <: StateEstimator{NT}
249253 P̂_0 = Hermitian (P̂_0, :L )
250254 P̂ = copy (P̂_0)
251255 K̂, M̂ = zeros (NT, nx̂, nym), zeros (NT, nx̂, nym)
256+ buffer = StateEstimatorBuffer {NT} (nx̂, nym)
252257 return new {NT, SM} (
253258 model,
254259 lastu0, x̂op, f̂op, x̂0, P̂,
255260 i_ym, nx̂, nym, nyu, nxs,
256261 As, Cs_u, Cs_y, nint_u, nint_ym,
257262 Â, B̂u, Ĉ, B̂d, D̂d,
258263 P̂_0, Q̂, R̂,
259- K̂, M̂
264+ K̂, M̂,
265+ buffer
260266 )
261267 end
262268end
@@ -402,6 +408,7 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
402408 γ:: NT
403409 m̂:: Vector{NT}
404410 Ŝ:: Diagonal{NT, Vector{NT}}
411+ buffer:: StateEstimatorBuffer{NT}
405412 function UnscentedKalmanFilter {NT, SM} (
406413 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂, α, β, κ
407414 ) where {NT<: Real , SM<: SimModel{NT} }
@@ -421,6 +428,7 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
421428 M̂ = Hermitian (zeros (NT, nym, nym), :L )
422429 X̂0, Ŷ0m = zeros (NT, nx̂, nσ), zeros (NT, nym, nσ)
423430 sqrtP̂ = LowerTriangular (zeros (NT, nx̂, nx̂))
431+ buffer = StateEstimatorBuffer {NT} (nx̂, nym)
424432 return new {NT, SM} (
425433 model,
426434 lastu0, x̂op, f̂op, x̂0, P̂,
@@ -429,7 +437,8 @@ struct UnscentedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
429437 Â, B̂u, Ĉ, B̂d, D̂d,
430438 P̂_0, Q̂, R̂,
431439 K̂, M̂, X̂0, Ŷ0m, sqrtP̂,
432- nσ, γ, m̂, Ŝ
440+ nσ, γ, m̂, Ŝ,
441+ buffer
433442 )
434443 end
435444end
@@ -698,6 +707,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
698707 M̂:: Matrix{NT}
699708 F̂_û:: Matrix{NT}
700709 Ĥ :: Matrix{NT}
710+ buffer:: StateEstimatorBuffer{NT}
701711 function ExtendedKalmanFilter {NT, SM} (
702712 model:: SM , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂
703713 ) where {NT<: Real , SM<: SimModel }
@@ -715,6 +725,7 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
715725 P̂ = copy (P̂_0)
716726 K̂, M̂ = zeros (NT, nx̂, nym), zeros (NT, nx̂, nym)
717727 F̂_û, Ĥ = zeros (NT, nx̂+ model. nu, nx̂), zeros (NT, model. ny, nx̂)
728+ buffer = StateEstimatorBuffer {NT} (nx̂, nym)
718729 return new {NT, SM} (
719730 model,
720731 lastu0, x̂op, f̂op, x̂0, P̂,
@@ -723,7 +734,8 @@ struct ExtendedKalmanFilter{NT<:Real, SM<:SimModel} <: StateEstimator{NT}
723734 Â, B̂u, Ĉ, B̂d, D̂d,
724735 P̂_0, Q̂, R̂,
725736 K̂, M̂,
726- F̂_û, Ĥ
737+ F̂_û, Ĥ,
738+ buffer
727739 )
728740 end
729741end
0 commit comments