diff --git a/src/estimator/mhe/construct.jl b/src/estimator/mhe/construct.jl index b22e07cfb..619ad598f 100644 --- a/src/estimator/mhe/construct.jl +++ b/src/estimator/mhe/construct.jl @@ -214,7 +214,13 @@ struct MovingHorizonEstimator{ U0, Ue = fill(NT(NaN), nu*He), fill(NT(NaN), nu*(He+1)) D0, De = fill(NT(NaN), nd*(He+1)), fill(NT(NaN), nd*(He+1)) X̂0_old = fill(NT(NaN), nx̂*He) - D0[1:nd] .= 0 # D0 start with d0(-1) and it should not be NaN + D0[1:nd] .= 0 # D0 starts with d0(-1) and it should not be NaN + if direct # the following windows all start at k=-1, thus replace the NaN values: + Yem[1:ny] .= @views model.yop[i_ym] + U0[1:nu] .= 0 + Ue[1:nu] .= model.uop + De[1:nd] .= model.dop + end x̂0arr_old = zeros(NT, nx̂) P̂arr_old = copy(cov.P̂_0) Nk = [0] diff --git a/test/2_test_state_estim.jl b/test/2_test_state_estim.jl index aab23e1e6..b47ebeee8 100644 --- a/test/2_test_state_estim.jl +++ b/test/2_test_state_estim.jl @@ -898,6 +898,11 @@ end @test mhe1.nxs == 2 @test mhe1.nx̂ == 6 @test size(mhe1.Ẽ, 2) == 6*mhe1.nx̂ + @test all(isfinite, mhe1.U0[1:2]) + @test all(isnan, mhe1.Y0m[1:2]) + @test all(isfinite, mhe1.Yem[1:2]) + @test all(isfinite, mhe1.D0[1:1]) + @test all(isfinite, mhe1.De[1:1]) mhe3 = MovingHorizonEstimator(linmodel, He=5, i_ym=[2]) @test mhe3.nym == 1 @@ -960,7 +965,7 @@ end mhe15 = MovingHorizonEstimator(linmodel; He=1, σP_0, covestim) @test mhe15.cov.invP̄ ≈ inv(covestim.cov.P̂) - function gcl(X̂e, _ , _ , _ , _ , _ , _ , _ , nx, ε) + function gcl(X̂e, _ , _ , _ , _ , _ , _ , _ , nc, ε) gc = X̂e .- 100 .- ε return [gc; zeros(nc .- length(X̂e))] end