TYPE_ROTATION_VECTOR, TYPE_ORIENTATION give different results, which are also with deviations

I implemented a listener for both the rotation vector and the orientation vector, although I know that it has depreciated. I wanted to check both.

I know that the rotation vector is a merge sensor and is recommended, but according to it to the north (the value [0] returned by GetOrientation (rotationMatrix, value) geaving bearing 0 ) does not coincide with the North from the orientation sensor. I also calculated from different applications from the game store, the values ​​of the orientation sensors seem to be closer to them.

In addition, many times my azimuth value [0] from Rotation_Vector, then getOrientation just shoots and continues to fluctuate between -180 and 180

PS "getRotationMatrix (float [] R, float [] I, float [] gravity, float [] geomagnetic)" also gives the same result as the 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 the phone’s axis Y and the β€œVector” pointer pointing north , so this was my initial implementation. Please suggest.

+7
android android-sensors magnetometer rotational-matrices
source share
1 answer

I think this will help ...

Android Compass that can compensate for deviation and pitch

This computes the North using more reliable sources.

Hope this helps.

+2
source share

All Articles