Skip to content

Commit 376d683

Browse files
authored
Merge pull request #426 from JuliaControl/debug_mhe_tc
debug: correctly fill the nonlinear equality constraints for `MovingHorizonEstimator` with non-`SingleShooting`
2 parents 56aa83a + 2d34426 commit 376d683

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎src/estimator/mhe/transcription.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ function con_nonlinprogeq_mhe!(
13831383
x̂dnext .+= ŵd
13841384
sdnext .= @. x̂dnext - x̂dnext_Z̃
13851385
end
1386-
Nk < He && (geq[nx̂*Nk+1:end] .= 0)
1386+
Nk < He && (geq[nx*Nk+1:end] .= 0)
13871387
return geq
13881388
end
13891389

@@ -1462,7 +1462,7 @@ function con_nonlinprogeq_mhe!(
14621462
sdnext .= @. x̂d_Z̃ - x̂dnext_Z̃ + 0.5*Ts*(k̇1 + k̇2)
14631463
sdnext .+= ŵd
14641464
end
1465-
Nk < He && (geq[nx̂*Nk+1:end] .= 0)
1465+
Nk < He && (geq[nx*Nk+1:end] .= 0)
14661466
return geq
14671467
end
14681468

‎test/2_test_state_estim.jl‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ end
11451145
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, ForwardDiff
11461146
using JuMP, Ipopt, DifferentiationInterface, SparseMatrixColorings, SparseConnectivityTracer
11471147
import ForwardDiff
1148+
11481149
linmodel = LinModel(sys,Ts,i_u=[1,2], i_d=[3])
11491150
linmodel = setop!(linmodel, uop=[10,50], yop=[50,30], dop=[5])
11501151
f(x,u,d,model) = model.A*x + model.Bu*u + model.Bd*d
@@ -1237,7 +1238,13 @@ end
12371238
end
12381239
preparestate!(mhe3, [50, 30], [5])
12391240
@test mhe3([5]) ≈ [50, 30] atol=1e-3
1240-
1241+
initstate!(mhe3, [10, 50], [50, 30], [5])
1242+
setstate!(mhe3, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
1243+
preparestate!(mhe3, [50, 30], [5])
1244+
updatestate!(mhe3, [10, 50], [50, 30], [5])
1245+
info = getinfo(mhe3) # test getinfo when Nk<He
1246+
@test info[:Ŵ] ≈ [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1247+
@test info[:V̂] ≈ [0.0, 0.0]
12411248

12421249
Q̂ = diagm([1/4, 1/4, 1/4, 1/4].^2)
12431250
R̂ = diagm([1, 1].^2)
@@ -1267,6 +1274,7 @@ end
12671274
end
12681275
preparestate!(mhe6, [13])
12691276
@test mhe6() ≈ [13] atol=1e-3
1277+
12701278
transcription = TrapezoidalCollocation(1)
12711279
mhe7 = MovingHorizonEstimator(
12721280
nonlinmodel_c; He=3, direct=true, transcription
@@ -1277,6 +1285,12 @@ end
12771285
end
12781286
preparestate!(mhe7, [13])
12791287
@test mhe7() ≈ [13] atol=1e-3
1288+
initstate!(mhe7, [0.0], [0.0])
1289+
setstate!(mhe7, [0.0, 0.0])
1290+
preparestate!(mhe7, [0.0])
1291+
info = getinfo(mhe7) # test getinfo when Nk<He
1292+
@test info[:Ŵ] ≈ [0.0, 0.0]
1293+
@test info[:V̂] ≈ [0.0]
12801294

12811295
# coverage of the branch with error termination status (with an infeasible problem):
12821296
mhe_infeas = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)

0 commit comments

Comments
 (0)