Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPE_ROTATION_VECTOR, TYPE_ORIENTATION give different results that too with deviation

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.

like image 401
pxm Avatar asked Jul 11 '13 21:07

pxm


1 Answers

I think this will help...

Android Compass that can Compensate for Tilt and Pitch

This calculates North using more reliable sources.

Hope this helps.

like image 145
chkdsk Avatar answered Oct 01 '22 01:10

chkdsk