Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getOrientation description does not match output values

Android getOrientation() function says that:

  • values at index 0: Azimuth is between pi and -pi
  • values at index 1: Pitch is between pi and -pi
  • values at index 2: Roll is between -pi/2 and pi/2

However I get different value ranges when testing with an emulator (Nexus 5 API 25)/device(Samsung API 21). I used Logcat to print the values. The pitch values I get are from -pi/2 to pi/2. With the screen pointing to the sky, the value ranges from 0 to -pi/2, with the screen pointing to the ground, it ranges from 0 to pi/2. And the roll goes above pi/2.

Why am I getting values different from the documentation?

My code is as following:

public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        System.arraycopy(event.values, 0, mAccelerometerReading,
                0, mAccelerometerReading.length);
    }
    else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        System.arraycopy(event.values, 0, mMagnetometerReading,
                0, mMagnetometerReading.length);
    }

    if (mAccelerometerReading != null && mMagnetometerReading != null) {
        // Update rotation matrix, which is needed to update orientation angles.
        mSensorManager.getRotationMatrix(mRotationMatrix, null,
                mAccelerometerReading, mMagnetometerReading);


        mSensorManager.getOrientation(mRotationMatrix, mOrientationAngles);

        Log.d("sensor", Float.toString(mOrientationAngles[1]));
    }
like image 669
Sarah cartenz Avatar asked Jun 22 '18 22:06

Sarah cartenz


1 Answers

Please Compare with the Real devices only(Preferable) Because Something Emulator gives different values than the Expected And here I am attaching one reference Please Have a look.

Reference 1

Reference 2

What you have do is:-

  1. Create Demo Application Which will print this pitch And rolls and then Compare it.
like image 91
Hitesh Anshani Avatar answered Nov 01 '22 21:11

Hitesh Anshani