-
Notifications
You must be signed in to change notification settings - Fork 253
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
Using asinf may leed to nan (not a number) #25
Comments
Thank you for raising the issue. The problem can be demonstrated using the following code. The plot ends after 45 samples because the remaining 55 samples are all NaN. import imufusion
import matplotlib.pyplot as pyplot
import numpy
numberOfSamples = 100
ahrs = imufusion.Ahrs()
pitch = numpy.empty(numberOfSamples)
for index in range(numberOfSamples):
ahrs.update_no_magnetometer(numpy.array([0, 0, 0]), numpy.array([1, 0, 0]), 1 / numberOfSamples)
pitch[index] = ahrs.quaternion.to_euler()[1]
pyplot.plot(pitch)
pyplot.show() After implementing the fix you have suggested, the plot shows all 100 samples as shown below. As an aside, it is interesting to note that the transition from the final |
The fix has been applied as commit d7788de. |
Thanks! We are going to use it in the next release :) |
Using 'asinf()' may lead to nan. In the function 'FusionQuaternionToEuler' a call is done to 'asinf', if the input of this is larger then 1 or less then -1, the result will be nan. All calculations using this pitch value (as a nan) will fail as well.
A potential solution might be something like:
float asinf_safe(float val) {
if (val >= 1.0f) { return (M_PI / 2.0f); }
if (val <= -1.0f) { return (M_PI / -2.0f); }
return asinf(val);
}
The text was updated successfully, but these errors were encountered: