0

I want to get best pitch and roll values. I'm already using that code to get azimut value.

Pitch and roll values seem not be good.

@Override
    public void onSensorChanged(SensorEvent event) {

        switch (event.sensor.getType()) {

            case Sensor.TYPE_ROTATION_VECTOR:
                // calculate th rotation matrix
                SensorManager.getRotationMatrixFromVector(rMat, event.values);

                float[] data = SensorManager.getOrientation(rMat, orientation);

                Log.i(TAG, "NEW pitch?="+data[1]+" roll="+data[2]);

                // do something with data

                break;
        }

I'm using that code in augmented reality environment (with Jmonkey engine) to move 3d objects depending on phone position :

public void updateRotationFused(float pitch, float roll) {
    //pitch: cams x axis roll: cams y axisheading: cams z axis
    mRotXYZQ.fromAngles(pitch + FastMath.HALF_PI , roll - FastMath.HALF_PI, 0);
    mCurrentCamRotationFused = mInitialCamRotation.mult(mRotXYZQ);
}

Is something I missed ?

EDIT

Code already in use in app is from this link

It works but I think Sensor.TYPE_ROTATION_VECTOR is a better way.

Florian Mac Langlade
  • 1,863
  • 7
  • 28
  • 57

1 Answers1

0

Accelerometers in mobile phones tend to be quite noisy and you need to apply a filter to get better results. This could be anything from a trimmed mean filter to a Kalman filter I suggest starting with a mean filter as it is pretty straight-forward to implement. Simply put it will cut off values too far from the most common ones based on a "window" size.

reden
  • 968
  • 7
  • 14