0

I know there are threads about this, and I have been reading them for days.

I think my issue is more specific. I'm trying to get the device rotationaround the y-axis.

If i'm correct, it is called azimuth

When I run the app, it returns 0.0 in logcat after debug logging values[0], values[1], & values[2]

Code:

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
        accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

        SensorEventListener SEL = new SensorEventListener() {
            @Override
            public void onSensorChanged(SensorEvent event) {

                mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);

                mSensorManager.getOrientation(rotationMatrix, values);

                accy = values[0];

                System.out.println(accy);
            }

            @Override
            public void onAccuracyChanged(Sensor sensor, int accuracy) {

            }
        };

        int rate = SensorManager.SENSOR_DELAY_GAME;
        mSensorManager.registerListener(SEL, accelerometer, rate);
        mSensorManager.registerListener(SEL, magnetometer, rate);

Logcat:

09-05 17:34:02.622    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802    6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
ahew
  • 116
  • 1
  • 3
  • 10

1 Answers1

1

From the code above the parameters gravity and geomagnetic in mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic); are probably zero array and thus your accy is always zero

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
  • Ok. Now, that seems obvious. I guess I dont fully understand the function so ill do some research. Thank you. – ahew Sep 06 '14 at 02:35
  • Take a look at http://stackoverflow.com/questions/17979238/android-getorientation-azimuth-gets-polluted-when-phone-is-tilted/17981374#17981374 – Hoan Nguyen Sep 06 '14 at 02:55
  • Perfect. This is what i've been trying to find. – ahew Sep 06 '14 at 14:33