From d760fad7668cce3c30f877cd8d07dca1d067e41a Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 4 Aug 2026 16:12:28 -0400 Subject: [PATCH 1/2] test: new disturb. reject test with `NonLinMPC` and `NonLinModel` It allows to test that the multiple shooting transcription work as expected, since the stochastic defect are treated separately as linear equality constraints. --- test/3_test_predictive_control.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/3_test_predictive_control.jl b/test/3_test_predictive_control.jl index 5603b81ed..ae02929b1 100644 --- a/test/3_test_predictive_control.jl +++ b/test/3_test_predictive_control.jl @@ -1128,6 +1128,25 @@ end end @test u ≈ [2] atol=1e-2 @test ym ≈ r atol=1e-2 + f(x,u,_,model) = model.A*x + model.Bu*u + h(x,_,model) = model.C*x + nlmodel = NonLinModel(f, h, linmodel.Ts, 1, 1, 1, 0, p=linmodel, solver=nothing) + u, ym = let nlmodel=nlmodel, r=r, outdist=outdist + estim = UnscentedKalmanFilter(nlmodel, nint_u=[1]) + nmpc_nint_ym = NonLinMPC(estim; Hp=10, transcription=MultipleShooting()) + nlmodel.x0 .= 0 + ym, u = nlmodel() - outdist, [0.0] + for i=1:25 + ym = nlmodel() - outdist + preparestate!(nmpc_nint_ym, ym) + u = moveinput!(nmpc_nint_ym, r) + updatestate!(nmpc_nint_ym, u, ym) + updatestate!(nlmodel, u) + end + u, ym + end + @test u ≈ [2] atol=1e-2 + @test ym ≈ r atol=1e-2 end @testitem "NonLinMPC and ManualEstimator v.s. default" setup=[SetupMPCtests] begin From 151b1bd185a686959664cdb4ab011d9d7d033ac8 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Tue, 4 Aug 2026 16:42:08 -0400 Subject: [PATCH 2/2] test: debug the new test --- test/3_test_predictive_control.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/3_test_predictive_control.jl b/test/3_test_predictive_control.jl index ae02929b1..6f4f636e9 100644 --- a/test/3_test_predictive_control.jl +++ b/test/3_test_predictive_control.jl @@ -1131,16 +1131,17 @@ end f(x,u,_,model) = model.A*x + model.Bu*u h(x,_,model) = model.C*x nlmodel = NonLinModel(f, h, linmodel.Ts, 1, 1, 1, 0, p=linmodel, solver=nothing) + nlmodel = setop!(nlmodel, yop=[10]) u, ym = let nlmodel=nlmodel, r=r, outdist=outdist estim = UnscentedKalmanFilter(nlmodel, nint_u=[1]) - nmpc_nint_ym = NonLinMPC(estim; Hp=10, transcription=MultipleShooting()) + nmpc_nint_u_ms = NonLinMPC(estim; Hp=10, transcription=MultipleShooting()) nlmodel.x0 .= 0 ym, u = nlmodel() - outdist, [0.0] for i=1:25 ym = nlmodel() - outdist - preparestate!(nmpc_nint_ym, ym) - u = moveinput!(nmpc_nint_ym, r) - updatestate!(nmpc_nint_ym, u, ym) + preparestate!(nmpc_nint_u_ms, ym) + u = moveinput!(nmpc_nint_u_ms, r) + updatestate!(nmpc_nint_u_ms, u, ym) updatestate!(nlmodel, u) end u, ym