From c13873a65357de9205afe1d9d312dc8eaae69f22 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 3 Aug 2026 16:02:30 -0400 Subject: [PATCH 1/4] debug: `initstate!(::StateEstimator)` reset `prepared` flag This is a minor debug to ensure that the user does not call `updatestate!` w/o `preparestate!` when `direct=true`. By reseting the flag, an error will be thrown in such cases. --- src/estimator/execute.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/estimator/execute.jl b/src/estimator/execute.jl index 1722c69aa..975584785 100644 --- a/src/estimator/execute.jl +++ b/src/estimator/execute.jl @@ -182,6 +182,7 @@ function initstate!(estim::StateEstimator, u, ym, d=estim.buffer.empty) init_estimate!(estim, estim.model, y0m, d0, u0) # --- init covariance error estimate, if applicable --- init_estimate_cov!(estim, y0m, d0, u0) + estim.prepared[] = false x̂ = estim.x̂0 + estim.x̂op return x̂ end From a86e6f050d2987f773f8363e683dfd493e301a20 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 3 Aug 2026 16:06:46 -0400 Subject: [PATCH 2/4] added: remove 1 allocation in `initstate!(::StateEstimator)` --- src/estimator/execute.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/estimator/execute.jl b/src/estimator/execute.jl index 975584785..5c08477ec 100644 --- a/src/estimator/execute.jl +++ b/src/estimator/execute.jl @@ -183,7 +183,8 @@ function initstate!(estim::StateEstimator, u, ym, d=estim.buffer.empty) # --- init covariance error estimate, if applicable --- init_estimate_cov!(estim, y0m, d0, u0) estim.prepared[] = false - x̂ = estim.x̂0 + estim.x̂op + x̂ = estim.buffer.x̂ + x̂ .= estim.x̂0 .+ estim.x̂op return x̂ end From c8be466138c892981a87b38424025b3014546346 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 3 Aug 2026 16:07:18 -0400 Subject: [PATCH 3/4] bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e499fca0f..cca0493a4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ModelPredictiveControl" uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c" -version = "2.9.1" +version = "2.9.2" authors = ["Francis Gagnon"] [deps] From 4540349b2ac2913719216744ef17086daaa39af1 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 3 Aug 2026 16:15:16 -0400 Subject: [PATCH 4/4] test: verify `prepared` flag after `initstate!` --- test/2_test_state_estim.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/2_test_state_estim.jl b/test/2_test_state_estim.jl index 98cd8a88d..e1953c3f1 100644 --- a/test/2_test_state_estim.jl +++ b/test/2_test_state_estim.jl @@ -75,6 +75,7 @@ end @test evaloutput(kalmanfilter1) ≈ kalmanfilter1() ≈ [50, 30] @test evaloutput(kalmanfilter1, d) ≈ kalmanfilter1(d) ≈ [50, 30] @test initstate!(kalmanfilter1, [10, 50], [50, 30+1]) ≈ [zeros(3); [1]] + @test kalmanfilter1.prepared[] == false linmodel2 = LinModel(append(tf(1, [1, 0]), tf(2, [10, 1])), 1.0) kalmanfilter2 = SteadyKalmanFilter(linmodel2, nint_u=[1, 1], direct=false) x = initstate!(kalmanfilter2, [10, 3], [0.5, 6+0.1])