How to calculate pitch and roll without magnetometer

209 Views Asked by At

In my app I am calculating azimuth, pitch and roll using accelerometer and magnetometer values:

        float[] rotationMatrix = new float[9];

        float[] inclinationMatrix = new float[9];

    private float[] mMagnetometerValue = new float[3]; //event.values
    private float[] mAccelerometerValue = new float[3]; //event.values

        SensorManager.getRotationMatrix(rotationMatrix, inclinationMatrix, mAccelerometerValue, mMagnetometerValue);

        // Orientation.

        float[] orientation = new float[3];

        SensorManager.getOrientation(rotationMatrix, orientation);

Now orientation array returns azimuth, pitch and roll. As documentation says getOrientation function:

values[0]: Azimuth, angle of rotation about the -z axis

values1: Pitch, angle of rotation about the x axis

values2: Roll, angle of rotation about the y axis.

Now good. But testing in another phone failed, because this phone has only accelerometer, not magnetometer, nor gyroscope or rotation vector sensor. After debugging I found that phone has device orientation sensor. Only doc I am found is this google gist.

Okay give a try. But this sensor returns only one float value, not float array. So I can not pass this as parameter to SensorManager.getRotationMatrix function.

Now question: How to retrieve pitch and roll with SensorManager.getRotationMatrix and SensorManager.getOrientation or without this functions using accelerometer and this device orientation sensor.

0

There are 0 best solutions below