1
votes

Most smartphones feature a 3-axis Gyroscope, a 3-axis magnetometer and a 3-axis accelerometer. Combining these sensors' measurements in a clever way (Kalman filter) should yield a fast, accurate, noise free and absolute device orientation. This could be stored as a quaternion or yaw/pitch/roll values.

What is the simplest way to achieve this in Android? Does the operating system already do those calculations for you? Are there open source implementations that one could use?

Most examples/tutorials I could find only focus on one type of sensor. But for my use case only the fusion of all three sensors via proper filtering would be of interest...

1

1 Answers

1
votes

You need to implements SensorEventListener interface. and in your class you must declare these :

Sensor sensor;
SensorManager sensorManager;

and override these methods:

public void onAccuracyChanged(Sensor sensor,int accuracy)
{

}

public void onSensorChanged(SensorEvent event)
{
}

and in constructor of your class(Activity or...)

sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
sensorManager.registerListener(this,sensor,SensorManager.SENSOR_DELAY_GAME);