1- struct SteadyKalmanFilter <: StateEstimator
2- model:: LinModel
1+ struct SteadyKalmanFilter{M <: LinModel } <: StateEstimator
2+ model:: M
33 x̂:: Vector{Float64}
44 i_ym:: Vector{Int}
55 nx̂:: Int
@@ -19,7 +19,7 @@ struct SteadyKalmanFilter <: StateEstimator
1919 Q̂:: Hermitian{Float64, Matrix{Float64}}
2020 R̂:: Hermitian{Float64, Matrix{Float64}}
2121 K:: Matrix{Float64}
22- function SteadyKalmanFilter (model, i_ym, nint_ym, Asm, Csm, Q̂, R̂)
22+ function SteadyKalmanFilter {M} (model:: M , i_ym, nint_ym, Asm, Csm, Q̂, R̂) where {M <: LinModel }
2323 nx, ny = model. nx, model. ny
2424 nym, nyu = length (i_ym), ny - length (i_ym)
2525 nxs = size (Asm,1 )
@@ -119,21 +119,21 @@ you can use 0 integrator on `model` integrating outputs, or the alternative time
119119[`KalmanFilter`](@ref).
120120"""
121121function SteadyKalmanFilter (
122- model:: LinModel ;
122+ model:: M ;
123123 i_ym:: IntRangeOrVector = 1 : model. ny,
124124 σQ:: Vector{<:Real} = fill (0.1 , model. nx),
125125 σR:: Vector{<:Real} = fill (0.1 , length (i_ym)),
126126 nint_ym:: IntVectorOrInt = fill (1 , length (i_ym)),
127127 σQ_int:: Vector{<:Real} = fill (0.1 , max (sum (nint_ym), 0 ))
128- )
128+ ) where {M <: LinModel }
129129 if nint_ym == 0 # alias for no output integrator at all :
130130 nint_ym = fill (0 , length (i_ym));
131131 end
132132 Asm, Csm = init_estimstoch (i_ym, nint_ym)
133133 # estimated covariances matrices (variance = σ²) :
134134 Q̂ = Diagonal {Float64} ([σQ ; σQ_int ]. ^ 2 );
135135 R̂ = Diagonal {Float64} (σR.^ 2 );
136- return SteadyKalmanFilter (model, i_ym, nint_ym, Asm, Csm, Q̂ , R̂)
136+ return SteadyKalmanFilter {M} (model, i_ym, nint_ym, Asm, Csm, Q̂ , R̂)
137137end
138138
139139@doc raw """
@@ -166,8 +166,8 @@ function updatestate!(estim::SteadyKalmanFilter, u, ym, d=Float64[])
166166end
167167
168168
169- struct KalmanFilter <: StateEstimator
170- model:: LinModel
169+ struct KalmanFilter{M <: LinModel } <: StateEstimator
170+ model:: M
171171 x̂:: Vector{Float64}
172172 P̂:: Hermitian{Float64, Matrix{Float64}}
173173 i_ym:: Vector{Int}
@@ -188,7 +188,7 @@ struct KalmanFilter <: StateEstimator
188188 P̂0:: Hermitian{Float64, Matrix{Float64}}
189189 Q̂:: Hermitian{Float64, Matrix{Float64}}
190190 R̂:: Hermitian{Float64, Matrix{Float64}}
191- function KalmanFilter (model, i_ym, nint_ym, Asm, Csm, P̂0, Q̂, R̂)
191+ function KalmanFilter {M} (model:: M , i_ym, nint_ym, Asm, Csm, P̂0, Q̂, R̂) where {M <: LinModel }
192192 nx, ny = model. nx, model. ny
193193 nym, nyu = length (i_ym), ny - length (i_ym)
194194 nxs = size (Asm,1 )
@@ -247,15 +247,15 @@ KalmanFilter estimator with a sample time Ts = 0.5 s, LinModel and:
247247```
248248"""
249249function KalmanFilter (
250- model:: LinModel ;
250+ model:: M ;
251251 i_ym:: IntRangeOrVector = 1 : model. ny,
252252 σP0:: Vector{<:Real} = fill (10 , model. nx),
253253 σQ:: Vector{<:Real} = fill (0.1 , model. nx),
254254 σR:: Vector{<:Real} = fill (0.1 , length (i_ym)),
255255 nint_ym:: IntVectorOrInt = fill (1 , length (i_ym)),
256256 σP0_int:: Vector{<:Real} = fill (10 , max (sum (nint_ym), 0 )),
257257 σQ_int:: Vector{<:Real} = fill (0.1 , max (sum (nint_ym), 0 ))
258- )
258+ ) where {M <: LinModel }
259259 if nint_ym == 0 # alias for no output integrator at all :
260260 nint_ym = fill (0 , length (i_ym));
261261 end
@@ -264,7 +264,7 @@ function KalmanFilter(
264264 P̂0 = Diagonal {Float64} ([σP0 ; σP0_int ]. ^ 2 );
265265 Q̂ = Diagonal {Float64} ([σQ ; σQ_int ]. ^ 2 );
266266 R̂ = Diagonal {Float64} (σR.^ 2 );
267- return KalmanFilter (model, i_ym, nint_ym, Asm, Csm, P̂0, Q̂ , R̂)
267+ return KalmanFilter {M} (model, i_ym, nint_ym, Asm, Csm, P̂0, Q̂ , R̂)
268268end
269269
270270@doc raw """
0 commit comments