I'm currently programming an Android AR application and I have an issue with my Azimuth calculation depending of the initial device tilt.
I use the ROTATION_VECTOR sensor to get Azimuth, Altitude and Tilt.
When I launch my application and the phone is perpendicular with ground, I have the good azimuth from the North. When I launch the application and the phone is parallel to the ground, I have bad values. I have also strange values when I change device tilt.
This is my code :
public void onSensorChanged(SensorEvent event)
{
if (event.sensor.getType() == sensor.TYPE_ROTATION_VECTOR)
{
SensorManager.getRotationMatrixFromVector(rotationVectorMatrix, event.values);
SensorManager.remapCoordinateSystem(rotationVectorMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, rotationMatrix);
SensorManager.getOrientation(rotationMatrix, orientation);
...
}
}
To get azimuth, you can use an accelerometer and magnetic field sensors. You can use following code to log azimuth value.
Source