Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/estimator/mhe/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ function add_data_windows!(estim::MovingHorizonEstimator, y0m, d0, u0=estim.last
Nk = estim.Nk[]
p = estim.direct ? 0 : 1 # u0 argument is u0(k-1) if estim.direct, else u0(k)
x̂0_old = estim.x̂0 # x̂0_old is x̂0(k-1|k-1) if estim.direct, else x̂0(k|k-1)
estim.Nk .+= 1
if !estim.direct || !estim.prepared[]
estim.Nk .+= 1 # direct=true: only increments if updatestate! was called
end
Nk = estim.Nk[]
ismoving = (Nk > estim.He)
# see MovingHorzionEstimator extended help for the exact time steps in each data window
Expand Down
7 changes: 7 additions & 0 deletions test/2_test_state_estim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,15 @@ end

mhe2 = MovingHorizonEstimator(linmodel, He=2)
preparestate!(mhe2, [50, 30], [5])
@test mhe2.Nk[] == 1
preparestate!(mhe2, [50, 30], [5])
@test mhe2.Nk[] == 1
x̂ = updatestate!(mhe2, [10, 50], [50, 30], [5])
@test mhe2.Nk[] == 1
@test x̂ ≈ zeros(6) atol=1e-9
@test mhe2.x̂0 ≈ zeros(6) atol=1e-9
preparestate!(mhe2, [50, 30], [5])
@test mhe2.Nk[] == 2
info = getinfo(mhe2)
@test info[:x̂] ≈ x̂ atol=1e-9
@test info[:Ŷ][end-1:end] ≈ [50, 30] atol=1e-9
Expand All @@ -1060,7 +1065,9 @@ end

mhe2 = MovingHorizonEstimator(linmodel, He=2, nint_u=[1, 1], nint_ym=[0, 0], direct=false)
preparestate!(mhe2, [50, 30], [5])
@test mhe2.Nk[] == 0
x̂ = updatestate!(mhe2, [10, 50], [50, 30], [5])
@test mhe2.Nk[] == 1
@test x̂ ≈ zeros(6) atol=1e-9
@test mhe2.x̂0 ≈ zeros(6) atol=1e-9
info = getinfo(mhe2)
Expand Down
Loading