Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_NavEKF2: init rngOnGnd to 5cm to avoid div-by-zero #18456

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

rmackay9
Copy link
Contributor

@rmackay9 rmackay9 commented Aug 25, 2021

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.

        // calculate range from ground plain to centre of sensor fov assuming flat earth
        ftype range = constrain_ftype((heightAboveGndEst/prevTnb.c.z),rngOnGnd,1000.0f);

        <snip>

        // divide velocity by range  to get predicted angular LOS rates relative to X and Y axes
        losPred[0] =  relVelSensor.y/range;
        losPred[1] = -relVelSensor.x/range;

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.

Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's consistent if nothing else :-)

@rmackay9 rmackay9 merged commit b524094 into ArduPilot:master Aug 26, 2021
@rmackay9
Copy link
Contributor Author

Cool, txs and merged!

@rmackay9 rmackay9 deleted the ekf2-optflow-div-by-zero-fix branch August 26, 2021 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants