I have implemented listener for both Rotation Vector and Orientation Vector though i know it's depreciated i wanted to test both.
I know Rotation Vector is a fusion sensor & recommended but according to it the NORTH (the value[0] returned by getOrientation(rotationMatrix,value) geaving bearing 0) doesn't matches with NORTH from Orientation sensor. I've also tallied from different apps from playstore, orientation sensor values seem to be more close to them.
Moreover many times my azimuth value[0] from Rotation_Vector then getOrientation just shoots up and keep oscillating between -180 to 180
P.S "getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic)" also gives same result as Rotation Vector.
public final void onSensorChanged(SensorEvent event)
{
float rotationMatrix[];
switch(event.sensor.getType())
{
.
.
.
case Sensor.TYPE_ROTATION_VECTOR:
rotationMatrix=new float[16];
mSensorManager.getRotationMatrixFromVector(rotationMatrix,event.values);
determineOrientation(rotationMatrix);
break;
case Sensor.TYPE_ORIENTATION:
sensorZValue.setText(""+event.values[0]); //rotation about geographical z axis
sensorXValue.setText(""+event.values[1]); //rotation about geographical x axis
sensorYValue.setText(""+event.values[2]); //rotation about geographical y axis
}//switch case ends
}
private void determineOrientation(float[] rotationMatrix)
{
float[] orientationValues = new float[3];
SensorManager.getOrientation(rotationMatrix, orientationValues);
double azimuth = Math.toDegrees(orientationValues[0]);
double pitch = Math.toDegrees(orientationValues[1]);
double roll = Math.toDegrees(orientationValues[2]);
sensorZValue.setText(String.valueOf(azimuth)); //rotation about geographical z axis
sensorXValue.setText(String.valueOf(pitch)); //rotation about geographical x axis
sensorYValue.setText(String.valueOf(roll)); //rotation about geographical y axis
}
I want to determine the angle between phone's Y axis and the Vector pointing North so that was my initial implementation. Please suggest.
I think this will help...
Android Compass that can Compensate for Tilt and Pitch
This calculates North using more reliable sources.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With