0

I have implemented an application that incorporates the following sensors:

  • Accelerometer
  • Magnetic Field
  • Orientation (deprecated)
  • Gyroscope
  • Gravity

This is a sample code of onSensorChanged() method:

        @Override
    public void onSensorChanged(SensorEvent event) {
        int type = event.sensor.getType();

        if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
            if (type == Sensor.TYPE_GYROSCOPE) {
                // Log.e(TAG, "Unreliable gyroscope");
            } else if (type == Sensor.TYPE_GRAVITY) {
                // Log.e(TAG, "Unreliable gravity");
            }
            return;
        }

        if (type == Sensor.TYPE_ACCELEROMETER) {
            mmAcceleration = event.values.clone();
        } else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
            mmGeomagnetic = event.values.clone();
        } else if (type == Sensor.TYPE_GYROSCOPE) {
            mmRotation = event.values.clone();
        } else if (type == Sensor.TYPE_ORIENTATION) {
            mmOrientation = event.values.clone();
        } else if (type == Sensor.TYPE_GRAVITY) {
            mmGravity = event.values.clone();
        }

        if (mmAcceleration != null && mmGeomagnetic != null
                && mmOrientation != null) {

                            // Handling the data ...

            mmAcceleration = null;
            mmGeomagnetic = null;
            mmRotation = null;
            mmOrientation = null;
            mmGravity = null;
        }
    }

The devices that I have tried the code on are HTC One S. I have tried it on 3 discrete devices. Also I have calibrated the G-sensor multiple times and then started the application but I still keep getting unreliable results. Also I have tried to calibrate, restart the phone and then calibrate again, or even after restart run directly my application. The other sensors work fine. Also I have tried different environments (indoor) and I am not close to any source of interference.

I still get unreliable (SENSOR_STATUS_UNRELIABLE) results for Gyroscope and gravity (uses gyroscope) sensors.

Do you have any suggestion about what may going wrong?

Thank you in advance.

npal
  • 529
  • 4
  • 11
  • Related read: http://www.thousand-thoughts.com/2012/03/android-sensor-fusion-tutorial/ – Morrison Chang Sep 06 '13 at 18:33
  • Thank you for the link, I am aware of that work. My problem is the event.accuracy == SENSOR_STATUS_UNRELIABLE for the gyroscope and the gravity sensor, not the sensor fusion. – npal Sep 06 '13 at 19:04
  • And I assume you've read: http://stackoverflow.com/questions/6256256/android-compass-seems-unreliable which I just realized is for compass and not gravity/gyro. – Morrison Chang Sep 06 '13 at 19:13
  • What frequency are you getting sensor data? – Morrison Chang Sep 06 '13 at 22:45
  • I am using SENSOR_DELAY_NORMAL for Gyroscope and SENSOR_DELAY_GAME for Gravity sensor. – npal Sep 13 '13 at 18:06

1 Answers1

0

I think what you might wanna go for is apply a "Complimentary Filter" or a "Kalman Filter" to the accelerometer data and Gyroscope data.... That should do the trick....