Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calibrate the orientation sensor in android?

I'm writing an app in Google Android 2.1 that needs to know which direction (n/w/s/e) the device (HTC Hero) is facing. The sensor and its listener are working great, but the values I get from the sensor are totally crappy. e.g. it tells me I'd be facing north when the device is facing SW or so...

This seems to be a known problem with android devices. The "solutions" I found on the web look like this:

  • shake the device around
  • move the device like an eight
  • tap on the devices back

This is thought to trigger the sensors recalibration. And: the thing with the "moving around" works for me... but that's not very professional I guess...

so - how do I trigger the recalibration of the orientation sensor from the SDK? I need the sensor to be properly calibrated without any fancy stuff that would make users of this app look like complete idiots while they are "manually" recalibrating their phones...

Is there any way to do this "right"?

EDIT:

Or: is there any way to determine PROGRAMMATICALLY, if the device is correctly calibrated or not? As a fallback-option so to speak... then I could warn the user that the device needs "manual" recalibration.

like image 399
xenonite Avatar asked Jul 04 '10 09:07

xenonite


1 Answers

I don't believe there is a way to know programatically if you compass sensor is calibrated correctly unless you use a secondary data source like GPS. If you can use GPS then when the user is moving you can compare the GPS movement with the compass heading and correct. Remember that local magnetic fields can screw up the compass readings and the devices has no idea if you are out in the middle of a forest or next to a transformer.

With these micro devices there is always a bit of skew you'll have to deal with. If you check the values for the accelerometer as well you'll see that at rest they aren't always returning 9.8 m/s^2 (or at least consistently between devices).

In your help you may just need to tell the user to rotate/twist their phone in a figure eight to reset the compass.

like image 192
Morrison Chang Avatar answered Oct 05 '22 15:10

Morrison Chang