4

I'm doing this project a part of which requires me to get the values of the acceleration of the phone(android) in each axis. So, for example, no matter how the phone is placed the value of the acceleration in z axis, if the phone is stationary, should be 9.8 and along the other axes, it should be 0. Now I went through a lot of threads to get this working properly. I tried doing what is suggested here

        trueacceleration[0] =(float) (accelerometervalues[0]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[2]*(-Math.sin(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])));
        trueacceleration[1] = (float) (accelerometervalues[0]*(-Math.cos(orientationvalues[2])*Math.sin(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.cos(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.cos(orientationvalues[0])) + accelerometervalues[2]*(Math.sin(orientationvalues[2])*Math.sin(orientationvalues[0])+ Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.cos(orientationvalues[0])));
        trueacceleration[2] = (float) (accelerometervalues[0]*(Math.sin(orientationvalues[2])*Math.cos(orientationvalues[1])) + accelerometervalues[1]*(-Math.sin(orientationvalues[1])) + accelerometervalues[2]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[1])));

But this gives me something totally different and changes as I move the phone around. Any idea what should be the correct/easiest way of doing this?

Community
  • 1
  • 1
copperhead
  • 647
  • 1
  • 9
  • 15
  • "if the phone is stationary, should be 9.8 and along the other axes, it should be 0. " i dont understand this, if the phone is stationary, the accelerometer wont report anything. – Glenn.nz Nov 09 '11 at 04:08
  • 1
    @Glenn.nz: If the phone is stationary, the accelerometer would return only the acceleration due to gravity – copperhead Nov 09 '11 at 08:59
  • No-- there may be a _force_ being applied to the phone, but if it is not moving, there will be no acceleration. If you drop the phone, you'll see your 9.8. – pents90 Nov 09 '11 at 18:28

1 Answers1

1

The accelerometer is influenced by gravity, even the device is sitting still on the table without any other force applied.

Taken from Android Developer:

A sensor of this type measures the acceleration applied to the device (Ad). Conceptually, it does so by measuring forces applied to the sensor itself (Fs) using the relation:

Ad = - ∑Fs / mass

In particular, the force of gravity is always influencing the measured acceleration:

Ad = -g - ∑F / mass

For this reason, when the device is sitting on a table (and obviously not accelerating), the accelerometer reads a magnitude of g = 9.81 m/s^2

As for converting device coordinates to world woordinates, why not use getRotationMatrix() instead?

NullUserException
  • 83,810
  • 28
  • 209
  • 234
variant-45
  • 391
  • 1
  • 7
  • can u tell me the exact steps to be taken? Currently I just multiply the rotation matrix with the accelerometer values vector. But the values that I get aren't correct because even if I rotate the phone the value along the z axis changes significantly. Also no matter how much force I apply to it, the values along the x and y coordinates remain as 0. – copperhead Nov 13 '11 at 03:54
  • @copperhead First you will need a sensor listener to get accelerometer and magnetometer values. After that, you can call getRotationMatrix(). [This article](http://nhenze.net/?p=561) give an example of using getRotationMatrix in augmented reality application. For accelerometer values, maybe you can try [this tutorial](http://mobilestrategist.blogspot.com/2010/01/android-accelerometer-and-orientation.html). – variant-45 Nov 13 '11 at 06:20