Skip to content

Commit 9b509f1

Browse files
committed
debug: pass f̂op, x̂op as arguments
1 parent ea8355c commit 9b509f1

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/estimator/execute.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ the function returns the next state of the augmented model, as deviation vectors
2929
where ``\mathbf{x̂_0}(k+1)`` is stored in `x̂0next` argument. The method mutates `x̂0next`,
3030
`û0` and `k0` in place. The argument `û0` stores the disturbed input of the augmented model
3131
``\mathbf{û_0}``, and `k0`, the intermediate stage values of `model.solver`, when applicable.
32-
The model parameter `model.p` is not included in the function signature for conciseness. See
33-
Extended Help for details on ``\mathbf{û_0, f̂}`` and ``\mathbf{ĥ}`` implementations.
32+
The model parameter `model.p` is not included in the function signature for conciseness.
33+
The operating points are handled inside ``\mathbf{f̂}``. See Extended Help for details on
34+
``\mathbf{û_0, f̂}`` and ``\mathbf{ĥ}`` implementations.
3435
3536
# Extended Help
3637
!!! details "Extended Help"
@@ -61,7 +62,7 @@ Extended Help for details on ``\mathbf{û_0, f̂}`` and ``\mathbf{ĥ}`` implem
6162
[`NonLinModel`](@ref)).
6263
"""
6364
function f̂!(x̂0next, û0, k0, estim::StateEstimator, model::SimModel, x̂0, u0, d0)
64-
return f̂!(x̂0next, û0, k0, model, estim.As, estim.Cs_u, x̂0, u0, d0)
65+
return f̂!(x̂0next, û0, k0, model, estim.As, estim.Cs_u, estim.f̂op, estim.x̂op, x̂0, u0, d0)
6566
end
6667

6768
"""
@@ -78,19 +79,19 @@ function f̂!(x̂0next, _ , _ , estim::StateEstimator, ::LinModel, x̂0, u0, d0)
7879
end
7980

8081
"""
81-
f̂!(x̂0next, û0, k0, model::SimModel, As, Cs_u, x̂0, u0, d0)
82+
f̂!(x̂0next, û0, k0, model::SimModel, As, Cs_u, f̂op, x̂op, x̂0, u0, d0)
8283
8384
Same than [`f̂!`](@ref) for [`SimModel`](@ref) but without the `estim` argument.
8485
"""
85-
function f̂!(x̂0next, û0, k0, model::SimModel, As, Cs_u, x̂0, u0, d0)
86+
function f̂!(x̂0next, û0, k0, model::SimModel, As, Cs_u, f̂op, x̂op, x̂0, u0, d0)
8687
# `@views` macro avoid copies with matrix slice operator e.g. [a:b]
8788
@views xd, xs = x̂0[1:model.nx], x̂0[model.nx+1:end]
8889
@views xdnext, xsnext = x̂0next[1:model.nx], x̂0next[model.nx+1:end]
8990
mul!(û0, Cs_u, xs) # ys_u = Cs_u*xs
9091
û0 .+= u0 # û0 = u0 + ys_u
9192
f!(xdnext, k0, model, xd, û0, d0, model.p)
9293
mul!(xsnext, As, xs)
93-
x̂0next .+= estim.f̂op .- estim.x̂op
94+
x̂0next .+= f̂op .- x̂op
9495
return nothing
9596
end
9697

src/estimator/kalman.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,11 +1067,17 @@ objects with the linearization points.
10671067
"""
10681068
function get_ekf_linfunc(NT, model, i_ym, nint_u, nint_ym, jacobian)
10691069
As, Cs_u, Cs_y = init_estimstoch(model, i_ym, nint_u, nint_ym)
1070-
f̂_ekf!(x̂0next, x̂0, û0, k0, u0, d0) = f̂!(x̂0next, û0, k0, model, As, Cs_u, x̂0, u0, d0)
1071-
ĥ_ekf!(ŷ0, x̂0, d0) = ĥ!(ŷ0, model, Cs_y, x̂0, d0)
1070+
nxs = size(As, 1)
1071+
x̂op, f̂op = [model.xop; zeros(nxs)], [model.fop; zeros(nxs)]
1072+
f̂_ekf!(x̂0next, x̂0, û0, k0, u0, d0) = f̂!(
1073+
x̂0next, û0, k0, model, As, Cs_u, f̂op, x̂op, x̂0, u0, d0
1074+
)
1075+
ĥ_ekf!(ŷ0, x̂0, d0) = ĥ!(
1076+
ŷ0, model, Cs_y, x̂0, d0
1077+
)
10721078
strict = Val(true)
10731079
nu, ny, nd, nk = model.nu, model.ny, model.nd, model.nk
1074-
nx̂ = model.nx + size(As, 1)
1080+
nx̂ = model.nx + nxs
10751081
x̂0next = zeros(NT, nx̂)
10761082
ŷ0 = zeros(NT, ny)
10771083
x̂0 = zeros(NT, nx̂)

0 commit comments

Comments
 (0)