1
- struct SteadyKalmanFilter <: StateEstimator
2
- model:: LinModel
1
+ struct SteadyKalmanFilter{M <: LinModel } <: StateEstimator
2
+ model:: M
3
3
x̂:: Vector{Float64}
4
4
i_ym:: Vector{Int}
5
5
nx̂:: Int
@@ -19,7 +19,7 @@ struct SteadyKalmanFilter <: StateEstimator
19
19
Q̂:: Hermitian{Float64, Matrix{Float64}}
20
20
R̂:: Hermitian{Float64, Matrix{Float64}}
21
21
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 }
23
23
nx, ny = model. nx, model. ny
24
24
nym, nyu = length (i_ym), ny - length (i_ym)
25
25
nxs = size (Asm,1 )
@@ -119,21 +119,21 @@ you can use 0 integrator on `model` integrating outputs, or the alternative time
119
119
[`KalmanFilter`](@ref).
120
120
"""
121
121
function SteadyKalmanFilter (
122
- model:: LinModel ;
122
+ model:: M ;
123
123
i_ym:: IntRangeOrVector = 1 : model. ny,
124
124
σQ:: Vector{<:Real} = fill (0.1 , model. nx),
125
125
σR:: Vector{<:Real} = fill (0.1 , length (i_ym)),
126
126
nint_ym:: IntVectorOrInt = fill (1 , length (i_ym)),
127
127
σQ_int:: Vector{<:Real} = fill (0.1 , max (sum (nint_ym), 0 ))
128
- )
128
+ ) where {M <: LinModel }
129
129
if nint_ym == 0 # alias for no output integrator at all :
130
130
nint_ym = fill (0 , length (i_ym));
131
131
end
132
132
Asm, Csm = init_estimstoch (i_ym, nint_ym)
133
133
# estimated covariances matrices (variance = σ²) :
134
134
Q̂ = Diagonal {Float64} ([σQ ; σQ_int ]. ^ 2 );
135
135
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̂)
137
137
end
138
138
139
139
@doc raw """
@@ -166,8 +166,8 @@ function updatestate!(estim::SteadyKalmanFilter, u, ym, d=Float64[])
166
166
end
167
167
168
168
169
- struct KalmanFilter <: StateEstimator
170
- model:: LinModel
169
+ struct KalmanFilter{M <: LinModel } <: StateEstimator
170
+ model:: M
171
171
x̂:: Vector{Float64}
172
172
P̂:: Hermitian{Float64, Matrix{Float64}}
173
173
i_ym:: Vector{Int}
@@ -188,7 +188,7 @@ struct KalmanFilter <: StateEstimator
188
188
P̂0:: Hermitian{Float64, Matrix{Float64}}
189
189
Q̂:: Hermitian{Float64, Matrix{Float64}}
190
190
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 }
192
192
nx, ny = model. nx, model. ny
193
193
nym, nyu = length (i_ym), ny - length (i_ym)
194
194
nxs = size (Asm,1 )
@@ -247,15 +247,15 @@ KalmanFilter estimator with a sample time Ts = 0.5 s, LinModel and:
247
247
```
248
248
"""
249
249
function KalmanFilter (
250
- model:: LinModel ;
250
+ model:: M ;
251
251
i_ym:: IntRangeOrVector = 1 : model. ny,
252
252
σP0:: Vector{<:Real} = fill (10 , model. nx),
253
253
σQ:: Vector{<:Real} = fill (0.1 , model. nx),
254
254
σR:: Vector{<:Real} = fill (0.1 , length (i_ym)),
255
255
nint_ym:: IntVectorOrInt = fill (1 , length (i_ym)),
256
256
σP0_int:: Vector{<:Real} = fill (10 , max (sum (nint_ym), 0 )),
257
257
σQ_int:: Vector{<:Real} = fill (0.1 , max (sum (nint_ym), 0 ))
258
- )
258
+ ) where {M <: LinModel }
259
259
if nint_ym == 0 # alias for no output integrator at all :
260
260
nint_ym = fill (0 , length (i_ym));
261
261
end
@@ -264,7 +264,7 @@ function KalmanFilter(
264
264
P̂0 = Diagonal {Float64} ([σP0 ; σP0_int ]. ^ 2 );
265
265
Q̂ = Diagonal {Float64} ([σQ ; σQ_int ]. ^ 2 );
266
266
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̂)
268
268
end
269
269
270
270
@doc raw """
0 commit comments