can't get [0,360°] angle from Accel from IMU sensor

Hi everyone,

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)

so I tried this :

Roll   = (atan2 (yAccel * abs(yAccel) , xAccel * abs(xAccel) + zAccel * abs(zAccel))) * 180/PI;
Pitch = (atan2 (xAccel * abs(xAccel) , yAccel * abs(yAccel) + zAccel * abs(zAccel))) * 180/PI;

The idea was to get rid of "sqrt" and to keep the sign of xAccel, yAccel and zAccel in the eq.
But I keep having the same problem...

is this wrong ? what can I do to get angles in all 4 quadrants ?
..please help !!

You can't get all four quadrants for both angles.

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.

Thanks for answering,

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° ?!

this is what I did:

     Ax_Rot = (atan2 (ay, az)) * 180/PI;
     Ay_Rot = (atan2 (ax, sqrt (ay*ay+az*az))) * 180/PI; 

     if (Ay_Rot >90) Ay_Rot -=90;
     if (Ay_Rot < -90) Ay_Rot +=90;

What I want is to get independent Pitch an Roll values in [0, 2*PI] (no matter how I rotate the sensor; xyz or yxz sequence)

jremington:
You can't get all four quadrants for both angles.

Can you please explain why ? Do you mean it's impossible ?

Can you please explain why ?

As is explained in the relevant section of the application note this is impossible.

At +/- 90 degrees tilt or roll, the Z axis acceleration is zero or very close to it, so you expect unstable values.

All angular systems have these problems, which is why everyone is switching to quaternions for attitude estimation.

OK,

And if I switch to quaternions, will I resolve the problem ?

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.

OK, thank you all ^^