@@ -200,22 +200,15 @@ end
200200
201201Initialize the steady-state Kalman gain `K̂` and estimation error covariance `P̂`.
202202"""
203- function init_skf (model :: LinModel{NT} , i_ym, Â, Ĉ, Q̂, R̂; direct= true ) where {NT <: Real }
204- ny, nym = model . ny , length (i_ym)
203+ function init_skf (i_ym, Â, Ĉ, Q̂, R̂; direct= true )
204+ ny, nym = size (Ĉ, 1 ) , length (i_ym)
205205 if ny != nym
206- R̂_y = zeros (NT , ny, ny)
206+ R̂_y = zeros (eltype (R̂) , ny, ny)
207207 R̂_y[i_ym, i_ym] = R̂
208- R̂_y = Hermitian (R̂_y, :L )
209- R̂ = R̂_y
208+ R̂ = Hermitian (R̂_y, :L )
210209 end
211210 K̂, P̂ = try
212- if pkgversion (ControlSystemsBase) ≥ v " 1.18.2"
213- ControlSystemsBase. kalman (Discrete, Â, Ĉ, Q̂, R̂; direct, extra= Val (true ))
214- else
215- K̂ = ControlSystemsBase. kalman (Discrete, Â, Ĉ, Q̂, R̂; direct)
216- P̂ = ControlSystemsBase. are (Discrete, Â' , Ĉ' , Q̂, R̂)
217- K̂, P̂
218- end
211+ ControlSystemsBase. kalman (Discrete, Â, Ĉ, Q̂, R̂; direct, extra= Val (true ))
219212 catch my_error
220213 if isa (my_error, ErrorException)
221214 error (" Cannot compute the optimal Kalman gain K̂ for the " *
@@ -225,7 +218,7 @@ function init_skf(model::LinModel{NT}, i_ym, Â, Ĉ, Q̂, R̂; direct=true) wh
225218 rethrow ()
226219 end
227220 end
228- if ny != nym
221+ if ny != nym
229222 K̂ = K̂[:, i_ym]
230223 end
231224 P̂ = Hermitian (P̂, :L )
@@ -572,7 +565,7 @@ struct UnscentedKalmanFilter{
572565 nx̂ = model. nx + nxs
573566 Â, B̂u, Ĉ, B̂d, D̂d, x̂op, f̂op = augment_model (model, As, Cs_u, Cs_y)
574567 Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :]
575- nσ, γ, m̂, Ŝ = init_ukf (model, nx̂, α, β, κ)
568+ nσ, γ, m̂, Ŝ = init_ukf (nx̂, α, β, κ)
576569 x̂0 = [zeros (NT, model. nx); zeros (NT, nxs)]
577570 K̂ = zeros (NT, nx̂, nym)
578571 M̂ = Hermitian (zeros (NT, nym, nym), :L )
733726
734727
735728@doc raw """
736- init_ukf(model, nx̂, α, β, κ) -> nσ, γ, m̂, Ŝ
729+ init_ukf(nx̂, α, β, κ) -> nσ, γ, m̂, Ŝ
737730
738731Compute the [`UnscentedKalmanFilter`](@ref) constants from ``α, β`` and ``κ``.
739732
@@ -753,14 +746,15 @@ covariance are respectively:
753746```
754747See [`update_estimate!(::UnscentedKalmanFilter)`](@ref) for other details.
755748"""
756- function init_ukf (:: SimModel{NT} , nx̂, α, β, κ) where {NT<: Real }
757- nσ = 2 nx̂ + 1 # number of sigma points
758- γ = α * √ (nx̂ + κ) # constant factor of standard deviation √P
749+ function init_ukf (nx̂, α, β, κ)
750+ α, β, κ = promote (α, β, κ)
751+ nσ = 2 nx̂ + 1 # number of sigma points
752+ γ = α * √ (nx̂ + κ) # constant factor of standard deviation √P
759753 m̂_0 = 1 - nx̂ / γ^ 2
760754 Ŝ_0 = m̂_0 + 1 - α^ 2 + β
761755 w = 1 / 2 / γ^ 2
762- m̂ = NT [m̂_0; fill (w, 2 * nx̂)] # weights for the mean
763- Ŝ = Diagonal (NT [Ŝ_0; fill (w, 2 * nx̂)]) # weights for the covariance
756+ m̂ = [m̂_0; fill (w, 2 * nx̂)] # weights for the mean
757+ Ŝ = Diagonal ([Ŝ_0; fill (w, 2 * nx̂)]) # weights for the covariance
764758 return nσ, γ, m̂, Ŝ
765759end
766760
0 commit comments