I'm currently using the ADXL345 3-axis accelerometer (part of the 6DOF IMU, incl ITG-3200 Gyro) to sense the pitch and roll angles.
acc_angle = atan2(acc_g,acc_g) * 180 / PI; acc_angle = atan2(acc_g,acc_g) * 180 / PI;
where acc_g = x-axis gravitational reading (g) acc_g = y-axis gravitational reading (g) acc_g = z-axis gravitational reading (g)
The above code makes use of the gravitational readings (g) of the accelerometer to measure the angular tilt. It works fine, however when the z-axis of the accelerometer goes parallel with the ground (ie. acc_g=0), the readings goes bonkers. I figured it's because of the trigo mathematics using atan2 then causes it when acc_g=0.
Any ideas on how to solve this problem?