Go Down

### Topic: Problems with angle estimation using ADXL345 (Read 2374 times)previous topic - next topic

#### hexaruby

##### Mar 07, 2012, 11:02 am
Hi

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.

Syntax:

acc_angle[0] = atan2(acc_g[0],acc_g[2]) * 180 / PI;
acc_angle[1] = atan2(acc_g[1],acc_g[2]) * 180 / PI;

where acc_g[0] = x-axis gravitational reading (g)
acc_g[1] = y-axis gravitational reading (g)
acc_g[2] = 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[2]=0), the readings goes bonkers. I figured it's because of the trigo mathematics using atan2 then causes it when acc_g[2]=0.

Any ideas on how to solve this problem?

#### ea123

#1
##### Mar 07, 2012, 01:26 pm
Hi,
the atan2 function should return 1.570 = PI/2 when the second argument is zero.

#### MarkT

#2
##### Mar 09, 2012, 11:03 am
Define "bonkers"
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### andresuq

#3
##### Jan 03, 2015, 09:44 pm
I'm using that sensor for measuring angular tilt, pitch and roll. I use this:

roll = (atan2(xg,sqrt(yg*yg+zg*zg)) * 180.0) / PI;
pitch = (atan2(yg,sqrt(xg*xg+zg*zg)) * 180.0) / PI;

the reading goes bonker too, when Z axe is parallel with floor...

how ddi you get a solution?

#### jremington

#4
##### Jan 04, 2015, 12:33 am
Define "bonker".

Go Up

Please enter a valid email to subscribe

To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy