From 0bf814cb4233e0786a096403d597b7479cb47e26 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 12 Oct 2026 14:41:17 -0400 Subject: [PATCH 1/2] debug: init `De` without a `NaN` if `direct==true` --- src/estimator/mhe/construct.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/estimator/mhe/construct.jl b/src/estimator/mhe/construct.jl index b22e07cfb..57bba187a 100644 --- a/src/estimator/mhe/construct.jl +++ b/src/estimator/mhe/construct.jl @@ -214,7 +214,8 @@ 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 + direct && (De[1:nd] .= model.dop) # De starts with d(-1) if p=0, thus similar x̂0arr_old = zeros(NT, nx̂) P̂arr_old = copy(cov.P̂_0) Nk = [0] From 9cc2550691af0f52ab3fbaf1519ec18b4d966960 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 12 Oct 2026 15:26:17 -0400 Subject: [PATCH 2/2] test: verify `NaN` in windows after MHE construction --- src/estimator/mhe/construct.jl | 7 ++++++- test/2_test_state_estim.jl | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/estimator/mhe/construct.jl b/src/estimator/mhe/construct.jl index 57bba187a..619ad598f 100644 --- a/src/estimator/mhe/construct.jl +++ b/src/estimator/mhe/construct.jl @@ -215,7 +215,12 @@ struct MovingHorizonEstimator{ 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 starts with d0(-1) and it should not be NaN - direct && (De[1:nd] .= model.dop) # De starts with d(-1) if p=0, thus similar + 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