Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't understand Android sample in documentation

Tags:

android

I'm trying to understand the documentation from Android for Sensor.TYPE_ACCELEROMETER: It gives this example:

It should be apparent that in order to measure the real acceleration of the device, the contribution of the force of gravity must be eliminated. This can be achieved by applying a high-pass filter. Conversely, a low-pass filter can be used to isolate the force of gravity.

public void onSensorChanged(SensorEvent event)
{
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter's time-constant
      // and dT, the event delivery rate

      final float alpha = 0.8;

      gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      linear_acceleration[0] = event.values[0] - gravity[0];
      linear_acceleration[1] = event.values[1] - gravity[1];
      linear_acceleration[2] = event.values[2] - gravity[2];
 }

But it says:
    All values are in SI units (m/s^2)
    values[0]: Acceleration **minus Gx** on the x-axis
    values[1]: Acceleration **minus Gy** on the y-axis
    values[2]: Acceleration **minus Gz** on the z-axis

So, should I remove the gravity from the values retrieved from accelerometer sensor or the gravity is already removed.

I mean, the example uses something called gravity[2] and uses the accelerometer, but then when I read the documentation it says that the values returned by the accelerometer already have the gravity substructed. That is what I don't understand.

And I assume gravity[] are the values from the gravity sensor, right? BTW, Any place where I can get detailed of how the two new sensors work? TYPE_LINEARACCELERATION and TYPE_ROTATIONVECTOR

Thanks in advance. Guillermo.

like image 895
polonskyg Avatar asked Aug 04 '26 16:08

polonskyg


1 Answers

I didn't get your question perfectly ..but If you want to use the sensor Gravity must be there. Just read the doc again .They already describe about your query.

and if you want to understand basic rule for sensor just follow this awesome tutorial.

Android Sensor Tutorial

like image 166
NovusMobile Avatar answered Aug 07 '26 07:08

NovusMobile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!