Question

I'm trying now to extract in Matlab information from android app that records output of accelerometer, gyrometer and magnetometer. As I need to find linear acceleration, I assumed that I can calculate it from accelerometer taking gravity into account. I thought that it should be possible to find by checking phone orientation based on magnetometer output (Earth magnetic field). But I can't get correct results with any formula. Am I right that it's possible to find gravity vector thanks to magnetometer? If so, how should I interpret sensor readings?

Was it helpful?

Solution

No, it is not possible to find the gravity from the magnetometer.


What you are looking for is called sensor fusion. I have implemented sensor fusion for the Shimmer platform based on this manuscript, it's basically a tutorial:

Direction Cosine Matrix IMU: Theory

Another resource I highly recommend is Sensor fusion on Android devices.

But why are you doing it yourself? The SensorManager already offers what you want.

OTHER TIPS

You can get linear acceleration by doing a low pass filter on accelerometer values to get gravity and then subtract accelerometer values from gravity. The code below is from http://developer.android.com/reference/android/hardware/SensorEvent.html

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];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top