Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Xoom accelererometer accuracy is always unreliable

I'm working on a simple compass type application for Android, testing on Xoom WiFi. The accuracy of the accelerometer readings is always SensorManager.SENSOR_STATUS_UNRELIABLE. The magnetic field readings are always accuracy SensorManager.SENSOR_STATUS_ACCURACY_HIGH. Could this be a bug in the Xoom, or is there a problem in my code?

onCreate:
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
accelGravitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

onResume:
mSensorManager.registerListener(accelListener, accelGravitySensor, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(magListener, magSensor, SensorManager.SENSOR_DELAY_NORMAL);

private final SensorEventListener accelListener = new SensorEventListener() {
  public void onSensorChanged(SensorEvent event) {
    Log.d(TAG, "accel (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ") accuracy=" + accuracyTag(event.accuracy));
  }
  public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
like image 880
Mitch Avatar asked May 12 '11 23:05

Mitch


3 Answers

It looks like a bug in the xoom. Check these posts:

http://community.developer.motorola.com/t5/Android-App-Development-for/Xoom-magnetometer-Y-axis-always-reads-zero/td-p/14184

http://community.developer.motorola.com/t5/Android-App-Development-for/Q-Compass-Behavior-when-Xoom-is-held-in-different-orientations/td-p/14332

like image 53
Aleadam Avatar answered Nov 01 '22 03:11

Aleadam


The Nexus S has this problem too (with the gyroscope), and it looks like it's due to a lazy driver writer who forgot to set the accuracy field of the reading ;)

As long as the data's fine, this should be purely cosmetic.

like image 32
vt. Avatar answered Nov 01 '22 03:11

vt.


I don't know if you're having problems with the compass accuracy, but I know I did when I used

magSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)

I highly recommend using something more like the following.

    mySensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> mySensors = mySensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
    if(mySensors.size() > 0){
        mySensorManager.registerListener(mySensorEventListener, mySensors.get(0), SensorManager.SENSOR_DELAY_NORMAL);
        sersorrunning = true;
        Toast.makeText(this, "Start ORIENTATION Sensor", Toast.LENGTH_LONG).show(); 
    }

I found that when I used the magnetic field sensor, rather than the orientation sensor, it worked pretty well on my phone (Droid Incredible), but wen all sorts of crazy on my wife's phone (Droid Pro), and my Coworker's phone (Samsung Galaxy Tab). So you might consider changing your sensor, just for device compatibility issues. :-)

like image 1
Jared Avatar answered Nov 01 '22 05:11

Jared