Jon Willis
Jon Willis

Reputation: 7024

Android - accelerometer on motodroid 1 reports incorrect values at first?

So I'm writing an app that detects movement, and needs to be calibrated to various movements. Over the past few days, I've noticed that right after a SensorEventListener is registered, onSensorChanged(SensorEvent) throws out incomplete (and therefore erroneous) .values[]. This behavior screws up my calibration process, and the amount of force that signifies a movement is way too high. I have verified that this is the case for every accelerometer logging app I have downloaded and tested, so its not an error specific to my code. I think this might be caused by bad hardware (possibly specific to my moto droid 1), or a software bug by the custom ROM I'm using (Simply Stunning 4.9, from Froyo 2.2.1 source.)

Example:

sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SENSOR_DELAY);
....
onSensorChanged(SensorEvent event){
    // event.values[0] = 0.0
    // event.values[1] = -0.47
    // event.values[2] = 0.0
}
....
onSensorChanged(SensorEvent event){
    // event.values[0] = 0.08
    // event.values[1] = -0.47
    // event.values[2] = 0.0
}
....
onSensorChanged(SensorEvent event){
   // event.values[0] = 0.08 
   // event.values[1] = -0.47 
   // event.values[2] = 10.1
}

As you can see, it often takes 2 readings before all of the correct values are accessible.

Can anyone confirm or deny this behavior on the moto droid 1 or other phone? Do you think a good solution is to just drop the first 2 or 3 readings so that they don't warp my calibration?

Upvotes: 2

Views: 418

Answers (1)

Dave MacLean
Dave MacLean

Reputation: 5173

Sounds reasonable to me. Perhaps you could register your listener at first with the FASTEST delay so you get those few bad readings out of the way quickly, then re-register with your desired update rate for your calibration. You could use two different listeners, the first one gets the crud out of the way, then unregisters itself and registers the other (good) one.

Upvotes: 2

Related Questions