What is the difference between "gravity" and "acceleration" sensors in Android?
Asked Answered
C

2

22

What is the difference between gravity and acceleration sensors in Android? From my point of view the physical value is the same in both cases.

Which one measures the force acting on unit mass inside the device?

ADDITION

The question is: what physical quantity is measured by these sensors? According to equivalence principle the acceleration and gravity are indistinguishable and the only way to measure both is by usual (but 3d) spring balance.

Chromolithograph answered 4/5, 2012 at 9:56 Comment(0)
B
12

Acceleration sensor gives you back the sum of all forces applied to your device, while Gravity sensor returns only the influence of gravity. If you want to exclude the gravity from acceleration, you may use a high-pass filter or just subtract the gravity sensor values from acceleration sensor values -- not sure which method gives better precision.

Another method could be using Sensor.TYPE_LINEAR_ACCELERATION, which gives exactly (acceleration - gravity), however you should check if it's available on the device. I've found a few devices, which have ACCELERATION sensor working, but no response from GRAVITY or LINEAR_ACCELERATION sensors.

Biancabiancha answered 4/5, 2012 at 10:43 Comment(8)
So you mean that gravity sensor is just acceleration sensor passed via low-pass filter?Chromolithograph
most probably, since GRAVITY became available since API version 9, and I don't think my phone got any hardware change when I have got it upgraded =)Biancabiancha
well,i've just tested, my old phone does not return any GRAVITY updates, though it runs the code without complains. maybe GRAVITY is a separate sensor, but if you are planning to support Android 2.1, probably high-pass filter on ACCELERATION sensor is your best bet.Biancabiancha
btw, why don't you use Sensor.TYPE_LINEAR_ACCELERATION instead? It gives exactly (acceleration - gravity), must be quite easy to use.Biancabiancha
LINEAR_ACCELERATION is also available since API 9: Field requires API level 9 (current min is 8): android.hardware.Sensor#TYPE_LINEAR_ACCELERATIONGiorgia
seems like a filter would produce a lot of potential error, especially if i want to try to double integrate acceleration to produce position. in my case at rest my calculations claim my device is travelling faster than light after only a few minutes!Macerate
Nice answer. FYI, TYPE_LINEAR_ACCELERATION and TYPE_GRAVITY are computed from accelerometer, magnetometer, and gyrometer data using a Kalman Filter, see source code github.com/android/platform_frameworks_base/tree/ics-mr1/…Stoecker
@lenik, do you mean getDefaultSensor is returning a non-null sensor for TYPE_GRAVITY and registerListener is returning true but onSensorChanged is never called?Impinge
O
3

This link might be helpful: http://www.sensorplatforms.com/which-sensors-in-android-gets-direct-input-what-are-virtual-sensors

The following excerpt summarize the answer for your question:

"The list... includes both physical sensors and sensor types with values derived from physical sensors, sometimes these are called virtual sensors... The virtual sensors types (gravity, linear acceleration, and rotation vector) provide values derived by combining the results from physical sensors intelligently... The rotation vector is a combination of the accelerometer, the magnetometer, and sometimes the gyroscope to determine the three-dimensional angle along which the Android device lays with respect to the Earth frame coordinates. By knowing the rotation vector of a device, accelerometer data can be separated into gravity and linear acceleration."

This link https://mcmap.net/q/52939/-android-gravity-sensor-type_gravity-for-2-1 also says that the gravity values are computed using a Butterworth filter.

Ossification answered 15/8, 2012 at 23:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.