Skip to content

Commit d57c13e

Browse files
authored
Merge pull request #156 from JuliaControl/debug_mhe_fallback
debug: fallback if nonfinite arr. cov. after correction/update
2 parents e83ee42 + c693b0f commit d57c13e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/estimator/mhe/execute.jl

+6
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,14 @@ function correct_cov!(estim::MovingHorizonEstimator)
441441
estim.covestim.P̂ .= estim.P̂arr_old
442442
try
443443
correct_estimate!(estim.covestim, y0marr, d0arr)
444+
all(isfinite, estim.covestim.P̂) || error("Arrival covariance P̄ is not finite")
444445
estim.P̂arr_old .= estim.covestim.
445446
invert_cov!(estim, estim.P̂arr_old)
446447
catch err
447448
if err isa PosDefException
448449
@error("Arrival covariance P̄ is not positive definite: keeping the old one")
450+
elseif err isa ErrorException
451+
@error("Arrival covariance P̄ is not finite: keeping the old one")
449452
else
450453
rethrow()
451454
end
@@ -461,11 +464,14 @@ function update_cov!(estim::MovingHorizonEstimator)
461464
estim.covestim.P̂ .= estim.P̂arr_old
462465
try
463466
update_estimate!(estim.covestim, y0marr, d0arr, u0arr)
467+
all(isfinite, estim.covestim.P̂) || error("Arrival covariance P̄ is not finite")
464468
estim.P̂arr_old .= estim.covestim.
465469
invert_cov!(estim, estim.P̂arr_old)
466470
catch err
467471
if err isa PosDefException
468472
@error("Arrival covariance P̄ is not positive definite: keeping the old one")
473+
elseif err isa ErrorException
474+
@error("Arrival covariance P̄ is not finite: keeping the old one")
469475
else
470476
rethrow()
471477
end

test/test_state_estim.jl

+15
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,21 @@ end
10031003
(:error, "Arrival covariance P̄ is not invertible: keeping the old one"),
10041004
ModelPredictiveControl.invert_cov!(mhe, Hermitian(zeros(mhe.nx̂, mhe.nx̂),:L))
10051005
)
1006+
mhe.P̂arr_old[1, 1] = Inf # Inf to trigger fallback
1007+
P̂arr_old_copy = deepcopy(mhe.P̂arr_old)
1008+
invP̄_copy = deepcopy(mhe.invP̄)
1009+
@test_logs(
1010+
(:error, "Arrival covariance P̄ is not finite: keeping the old one"),
1011+
preparestate!(mhe, [50, 30], [5])
1012+
)
1013+
@test mhe.P̂arr_old P̂arr_old_copy
1014+
@test mhe.invP̄ invP̄_copy
1015+
@test_logs(
1016+
(:error, "Arrival covariance P̄ is not finite: keeping the old one"),
1017+
updatestate!(mhe, [10, 50], [50, 30], [5])
1018+
)
1019+
@test mhe.P̂arr_old P̂arr_old_copy
1020+
@test mhe.invP̄ invP̄_copy
10061021
end
10071022

10081023
@testset "MovingHorizonEstimator set constraints" begin

0 commit comments

Comments
 (0)