From d293c4231ded671d6c87a71d77641501e3172161 Mon Sep 17 00:00:00 2001 From: Paul Riseborough Date: Wed, 11 Oct 2017 21:54:47 +1100 Subject: [PATCH] EKF: Protect against divide by zero caused by invalid optical flow --- EKF/estimator_interface.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EKF/estimator_interface.cpp b/EKF/estimator_interface.cpp index 283b435630..3b28b99297 100644 --- a/EKF/estimator_interface.cpp +++ b/EKF/estimator_interface.cpp @@ -278,7 +278,13 @@ void EstimatorInterface::setOpticalFlowData(uint64_t time_usec, flow_message *fl // check if enough integration time and fail if integration time is less than 50% // of min arrival interval because too much data is being lost float delta_time = 1e-6f * (float)flow->dt; - bool delta_time_good = (delta_time >= 5e-7f * (float)_min_obs_interval_us); + float delta_time_min = 5e-7f * (float)_min_obs_interval_us; + bool delta_time_good = delta_time >= delta_time_min; + if (!delta_time_good) { + // protect against overflow casued by division with very small delta_time + delta_time = delta_time_min; + } + // check magnitude is within sensor limits float flow_rate_magnitude;