16

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.

S.L. Barth
  • 7,954
  • 71
  • 47
  • 62
xenonite
  • 1,631
  • 4
  • 28
  • 43
  • 1
    once I see an compass application on the market. this application gives a message if the magnetic field traction is bad. I don't know how this works so I'm interested in this answer either – Michel Jul 04 '10 at 19:07

2 Answers2

3

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.

Morrison Chang
  • 10,296
  • 3
  • 32
  • 60
  • thanks for your answer, but sadly i cannot use gps within this app at all. problem is, i had my htc hero returning me total nonesense all the time until i get it to recalibrate its sensor. i really need to know how to trigger this by sdk/ndk... – xenonite Jul 04 '10 at 21:39
  • 1
    There is a forum where they have mentioned some shell instructions to force the sensors into writing a new settings file, but it requires using the su command, which means you might not be able to use it in a normal android version... other than that, you could open a shell through Java, and type those commands, even though a reboot is necessary for it to take effect, assuming it works anyway. You can check the link here: http://forum.xda-developers.com/showpost.php?p=4081673&postcount=4885 – Luis Miguel Serrano Jul 04 '10 at 22:14
  • That GPS calibration method would only work if you instruct the user to point the phone in the direction of motion, right? Or am I missing something? – MatrixFrog Jul 24 '10 at 07:39
  • I think only a consistent orientation wrt motion is needed to use GPS calibration of the compass. Say the user is moving northeast and then makes a turn heading west. As long as the user holds the unit in the same orientation (on the dashboard or in the hand) the compass should change appropriately and if it doesn't match the GPS reading well then that's the correction factor. – Morrison Chang Jul 24 '10 at 17:54
0

I assume you are referring to the Magnetometer inside the Hero.

Callibrating it is a tough one and will/should always require user interaction for a realiable callibration. There are seperate strategies to deal with that. You could ask users to hold there device in north direction and then recallibrate. If the users don't know where north is, you can ask them to direct zhe device towards the sun and based on location and time you can calculate where that is.

Leaving callibration aside, I would guess that your problem is that the readings you get from the sensor are inaccurate. Of course callibration is a prerequisite for accurate readings, but there are also other factors in play.

It is common practice to complement sensor data from one sensor with the data a different sensor to increase accuracy. You could use the GPS to determine a heading when the user is moving. If he's moving slowly however, this is inaccurate as well. You could integrate the data reported by the Accelerometer to guess about orientation changes (not the absolute orientation). But honestly a Gyrometer would be more ideal in this case.

Systems that work like this are sometimes called Inertial Navigation Systems (INS) because they can, given a fixed point in space, determine their subsequent relative position and orientation accurately without further external data. Using a Kalman filter is common practice to recallibrate the system from time to time when an absolute position (e.g. retrieved via GPS) is available.

Although it is unrealistic to implement a full-fledged INS, you can certainly draw a few ideas from how they work to make your orientation readings more accurate.

Johannes Rudolph
  • 34,073
  • 12
  • 105
  • 164