Skip to content

Commit f3384a8

Browse files
committed
changed: bumping ControlSystemsBase compat once more
To avoid the intricate `pkgversion` branching.
1 parent 16ae1e3 commit f3384a8

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
2121
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
2222

2323
[compat]
24-
ControlSystemsBase = "1.9"
24+
ControlSystemsBase = "1.18.2"
2525
DAQP = "0.6, 0.7.1"
2626
DifferentiationInterface = "0.6.45, 0.7"
2727
Documenter = "1"

src/estimator/kalman.jl

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,15 @@ end
200200
201201
Initialize 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] =
208-
R̂_y = Hermitian(R̂_y, :L)
209-
= R̂_y
208+
= 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-
= ControlSystemsBase.kalman(Discrete, Â, Ĉ, Q̂, R̂; direct)
216-
= 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̂[:, i_ym]
230223
end
231224
= 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
= zeros(NT, nx̂, nym)
578571
= Hermitian(zeros(NT, nym, nym), :L)
@@ -733,7 +726,7 @@ end
733726

734727

735728
@doc raw"""
736-
init_ukf(model, nx̂, α, β, κ) -> nσ, γ, m̂, Ŝ
729+
init_ukf(nx̂, α, β, κ) -> nσ, γ, m̂, Ŝ
737730
738731
Compute the [`UnscentedKalmanFilter`](@ref) constants from ``α, β`` and ``κ``.
739732
@@ -753,14 +746,15 @@ covariance are respectively:
753746
```
754747
See [`update_estimate!(::UnscentedKalmanFilter)`](@ref) for other details.
755748
"""
756-
function init_ukf(::SimModel{NT}, nx̂, α, β, κ) where {NT<:Real}
757-
= 2nx̂ + 1 # number of sigma points
758-
γ = α * (nx̂ + κ) # constant factor of standard deviation √P
749+
function init_ukf(nx̂, α, β, κ)
750+
α, β, κ = promote(α, β, κ)
751+
=2nx̂ + 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-
= 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̂_0; fill(w, 2 * nx̂)] # weights for the mean
757+
= Diagonal([Ŝ_0; fill(w, 2 * nx̂)]) # weights for the covariance
764758
return nσ, γ, m̂, Ŝ
765759
end
766760

0 commit comments

Comments
 (0)