Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does x,y,z values obtained from accelerometer in Android indicate?

Tags:

android

At first I thought:

  • x - tilting the phone from left - right and vice versa
  • y - upside down and vice versa
  • z - lifting the phone up and down

But it doesn't seem like that. Can anyone correct me if I am wrong.

I want to know these values in-order to know the angle of the phone. Is it possible to know it using these values?

like image 409
user3436096 Avatar asked May 26 '14 13:05

user3436096


1 Answers

Acceleration is a vector quantity, i.e. it has importance of its magnitude and also direction in which it is occurring.

Keeping this is mind and see image in link provided by Nicolai Ditlev Krogh Krüger, what we get is the right side of your phone is positive X direction, top side is positive Y direction and the screen side is positive Z direction.

Now Force=mass x acceleration

therefore acceleration = force/mass

Now force of gravity always acts on your device. To keep it from falling you have to apply equal force but in "OPPOSITE" direction.

Now when you put your phone on horizontal table, the table applies an upward force (from back of phone towards the screen), this is positive Z direction. So acceleration here is force/mass of your phone in positive Z direction. Since phone is not moving, means force by table equals gravity and there is no other force in any other directions as well. Force by gravity = mass x 9.8 (approx). Thus you see a value close to +10 for Z parameter of accelerometer and other two are near to zero.

Take one more example. This time hold your phone such that right side of phone is down and left side is up, and you hold your phone from near its ear piece and mic (opposite edges). In this scenario you are applying force against gravity upward, to keep your phone from falling, in negative X direction (remember that in phone positive X direction is pointing towards right side of phone). Thus you will see a value close to -10 for X parameter of accelerometer.

If user holds the phone at an angle (say a) from the horizontal plane (assume user tilt right side of phone down), then force of gravity becomes mass x 9.8 x Cos(a), where 'a' is in degree not radian, along the phone's X axis. Thus acceleration now becomes 9.8 x Cos(a). Since Max value of Cos(a)=1 (at a=0 degree), user will see a value less than 9.8 for X parameter of accelerometer for any other angle. If angle a= 60 degree (approx) then X parameter will show value close to 5, as Cos(60)= 0.5.

This is how the values change in the accelerometer output.

User can use the values of X, Y & Z to calculate actual angle of tilt of device from any plane (say horizontal plane).

Suppose X parameter is showing value 6. Then tilt is aCos(6/9.8) (that is Cos inverse and result will be in radians). To convert radians to degrees multiply by 180/pi. Thus final angle of tilt 'a' = aCos(6/9.8)*(180/pi) in degrees.

This how you come to know the tilt of your phone and use it to simulate force on digital objects on the screen. More tilt means more acceleration and hence more force.

like image 167
Kaustuv Avatar answered Nov 15 '22 08:11

Kaustuv