Search code examples
androidvectoropengl-esrotationsensormanager

Android Sensor Manager Rotation Vector (TYPE_ROTATION_VECTOR) unreliable / slow


I´m currently facing some problems in reading out the values of the Android rotation vector. As the Android documentation explains, the rotation vector is a sensor fusion combination of gyroscope, magnetometer and acceleromenter. The reference frame of the rotation vector is X facing east, Y facing north and Z vertical when the device is laying in a flat position.

All the mentioned characteristics are right and work in my application.

Now the problem: The rotation vector seems partly very inaccurate. First the values of the rotation vector seem to lag behind the actual movement, second the values are really affected by fast movements of de device.

To exclude any errors made by my implementation is tested a demo application from google as well. The source code is located here. Also in this demo the rotation vector seems partly laggy and unreliable in fast movements.

Did anyone else faced some problems with Androids rotation vector?

Here is how I´m doing it: Register the sensor and listener:

sensorManager.registerListener(this, gravitySensor, SensorManager.SENSOR_DELAY_FASTEST, handler)

Reading out the values and create a rotation matrix used for OpenGL rendering:

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
        SensorManager.getRotationMatrixFromVector(rotationMatrix4D, event.values);
    }
}

Edit: I am developing on Samsung Galaxy S3 Mini. Maybe just the device's sensors are not that good.


Solution

  • After deep investigating Android's Rotation Vector on different devices I recognized that this sensor indeed is really inaccurate.

    So there are a lot of possibilities to get a more accurate and stable orientation. 1. Smooth the Rotation Vector over time 2. Perform a sensor fusion with the Ratation Vector and for example the gyroscope.

    My approach was to store the initial rotation vector and then use the gyroscope to calculate the actual orientation of the device. Since the gyroscope is likely to be affected by drift, i reset the orientation every few seconds the the orientation of the rotation vector.