I'm working with an Arduino and an IMU sensor.
I want to get the Pitch an Roll angles (in all 4 quadrants) from [-pi ,pi] or [0,360°]...so I used the "atan2".
the original eq. are :
[/code]
Roll = atan2 ( yAccel , sqrt(sq(xAccel)+sq(zAccel))) * 180/PI; // in degree
Pitch = atan2 ( xAccel , sqrt(sq(yAccel)+sq(zAccel))) * 180/PI;
[/code]
Due to "sqrt" (always positive) these eq. won't give me the 4 quadrants, I only get angles between [-90, 90] (quadrant 1 and 4)
First, your code isn't correct, and will work properly only if you tilt on one axis at a time. Use either equations 25 & 26 or 28 & 29 (with atan2) in this application note.
Second, read the section "Eliminating Duplicate Solutions by Limiting the Roll and Pitch Ranges" in the application note.
I already tried both 25&26 eq. and 28&29 eq.
I know It may be silly but that's how I got my eq. (combining both solutions)
Using 25&26 eq...I couldn't always guarantee stable values for Pitch or Roll angles...
For exp if I only rotate the sensor 90° around Y-Axis (Pitch angle), I get wrong values for Roll angle (I should only get 0°, because I didn't rotate around X-Axis..Am I wrong ?)...Unstable sensor around -90° and 90° ?!
Quarternions have no gimbal lockup, which in general is a good thing. You have to live with
each 3D-rotation having two representations, but that's easy, just normalize to a positive real part.