DavidEGrayson / minimu9-ahrs

Program for reading data from the Pololu MinIMU-9 over I²C. Works on the Raspberry Pi and other embedded ARM Linux boards.
Other
167 stars 68 forks source link

minimu9-ahrs.cpp/fuse_default(): comparing integer with floating point #17

Closed nxdefiant closed 7 years ago

nxdefiant commented 9 years ago

Near line 137 of minimu9-ahrs.cpp you are using abs() to compare with a float, however abs() only returns an integer, so its always zero for -1 < x < 1 You might want to use fabs() instead.

if (abs(acceleration.norm() - 1) <= 0.3)
{
}
DavidEGrayson commented 9 years ago

Oh, good catch. So the result of this bug would be that the code applies corrections from the accelerometer in way more situations than it was intended to; basically that if statement will almost always be true. It would only be false if the acceleration.norm() were exactly 0, or more than 2.