Using getRotationMatrix and getOrientation in Android 2.1

Posted by aaronmar on Stack Overflow See other posts from Stack Overflow or by aaronmar
Published on 2010-06-03T06:20:55Z Indexed on 2010/06/03 6:24 UTC
Read the original article Hit count: 894

Filed under:
|
|
|
|

I've been having issues with this for far too long. This code should output dx,dy,dz for the accelerometer, and a running total of the dx. It should also output azimuth, pitch, and roll.

I've used info from http://bit.ly/codeUsed, but to no avail.

This code does not correctly output pitch, azimuth, or roll. It outputs 0.0, -0.0, -0.0 for the last three textviews, respectively.

Please restore my sanity by helping me

switch (event.sensor.getType()) {
            case Sensor.TYPE_ACCELEROMETER:
                accelerometerValues = event.values.clone();
            case Sensor.TYPE_MAGNETIC_FIELD:
                geomagneticMatrix = event.values.clone();
                sensorReady = true;
                break;
            default:
                break;
        }   

        if (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
            sensorReady = false;

            float[] R = new float[16];
            float[] I = new float[16];

            SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);

            float[] actual_orientation = new float[3];
            SensorManager.getOrientation(R, actual_orientation);

            tvXCoordinate.setText(accelerometerValues[0] + "");
            tvYCoordinate.setText(accelerometerValues[1] + "");
            tvZCoordinate.setText(accelerometerValues[2] + "");

            floatXTotal += accelerometerValues[0];
            tvXTotal.setText(floatXTotal + "");

            tvAzimuth.setText(actual_orientation[0] + "");
            tvPitch.setText(actual_orientation[1] + "");
            tvRoll.setText(actual_orientation[2] + "");
        }

© Stack Overflow or respective owner

Related posts about java

Related posts about android