Skip to content

Commit

Permalink
Fix NaN when rejectionTimeout is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
xioTechnologies authored Jun 13, 2022
1 parent d7788de commit a0dfea6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Fusion/FusionAhrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,13 @@ FusionVector FusionAhrsGetEarthAcceleration(const FusionAhrs *const ahrs) {
* @return AHRS algorithm internal states.
*/
FusionAhrsInternalStates FusionAhrsGetInternalStates(const FusionAhrs *const ahrs) {
const float rejectionTimeoutReciprocal = 1.0f / (float) ahrs->settings.rejectionTimeout;
const FusionAhrsInternalStates internalStates = {
.accelerationError = FusionRadiansToDegrees(FusionAsin(2.0f * FusionVectorMagnitude(ahrs->halfAccelerometerFeedback))),
.accelerometerIgnored = ahrs->accelerometerIgnored,
.accelerationRejectionTimer = (float) ahrs->accelerationRejectionTimer * rejectionTimeoutReciprocal,
.accelerationRejectionTimer = ahrs->settings.rejectionTimeout == 0 ? 0.0f : (float) ahrs->accelerationRejectionTimer / (float) ahrs->settings.rejectionTimeout,
.magneticError = FusionRadiansToDegrees(FusionAsin(2.0f * FusionVectorMagnitude(ahrs->halfMagnetometerFeedback))),
.magnetometerIgnored = ahrs->magnetometerIgnored,
.magneticRejectionTimer = (float) ahrs->magneticRejectionTimer * rejectionTimeoutReciprocal,
.magneticRejectionTimer = ahrs->settings.rejectionTimeout == 0 ? 0.0f : (float) ahrs->magneticRejectionTimer / (float) ahrs->settings.rejectionTimeout,
};
return internalStates;
}
Expand Down

0 comments on commit a0dfea6

Please sign in to comment.