Skip to content

Commit 2ed9d57

Browse files
committed
debug UKF
1 parent 21bd589 commit 2ed9d57

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/estimator/kalman.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function update_estimate!(estim::UnscentedKalmanFilter{NT}, u, ym, d) where NT<:
567567
nym, nx̂, nσ = estim.nym, estim.nx̂, estim.
568568
γ, m̂, Ŝ = estim.γ, estim.m̂, estim.
569569
# --- initialize matrices ---
570-
= Matrix{NT}(undef, nx̂, nσ)
570+
, X̂_next = Matrix{NT}(undef, nx̂, nσ), Matrix{NT}(undef, nx̂, nσ)
571571
ŷm = Vector{NT}(undef, nym)
572572
= Vector{NT}(undef, estim.model.ny)
573573
Ŷm = Matrix{NT}(undef, nym, nσ)
@@ -600,7 +600,7 @@ function update_estimate!(estim::UnscentedKalmanFilter{NT}, u, ym, d) where NT<:
600600
X̂_cor .= x̂_cor
601601
X̂_cor[:, 2:nx̂+1] .+= γ_sqrt_P̂_cor
602602
X̂_cor[:, nx̂+2:end] .-= γ_sqrt_P̂_cor
603-
X̂_next = X̂_cor
603+
X̂_next = similar(X̂_cor)
604604
for j in axes(X̂_next, 2)
605605
@views f̂!(X̂_next[:, j], estim, estim.model, X̂_cor[:, j], u, d)
606606
end

src/model/nonlinmodel.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,19 @@ h!(y, model::NonLinModel, x, d) = model.h!(y, x, d)
130130

131131
typestr(model::NonLinModel) = "nonlinear"
132132

133+
function rk4!(x, u, d)
134+
xterm .= x
135+
fc!(ẋ, xterm, u, d)
136+
k1 .=
137+
xterm .= @. x + k1 * Ts/2
138+
fc!(ẋ, xterm, u, d)
139+
k2 .=
140+
xterm .= @. x + k2 * Ts/2
141+
fc!(ẋ, xterm, u, d)
142+
k3 .=
143+
xterm .= @. x + k3 * Ts
144+
fc!(ẋ, xterm, u, d)
145+
k4 .=
146+
x .+= @. (k1 + 2k2 + 2k3 + k4)*Ts/6
147+
return x
148+
end

0 commit comments

Comments
 (0)