AP_NavEKF2: init rngOnGnd to 5cm to avoid div-by-zero #18456
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is the equivalent of PR #17577 but for EKF2. This issue was reported as part of 4.1 beta testing.
This resolves a crash in SITL by ensuring that the rngOnGnd is never zero and thus avoids a divide-by-zero when fusing optical flow measurements here in AP_NavEKF2_OptFlowFusion.cpp.
The problem is in the lines shown below. "range" can be zero because "rngOnGnd" can be zero which leads to the div-by-zero. We fix this by simply initialising rngOnGnd to 5cm and from then on it can never be set back to zero.
Testing has been only in SITL but I have checked before and after that this resolves the divide-by-zero. I think from inspection it is also clear that this is a safe change.