views:

417

answers:

2

I need to build compass for my application.

From reading the documentation it seems there are two reasonable ways of doing this:

  • Sensor.TYPE_ORIENTATION method: This is the easy way of doing it. The problem with this is it is not accurate. When I compare my reading with Snaptic Compass it is about 10-15 degress off which for my purposes is unacceptable.
  • Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_MAGNETIC_FIELD and getRotationMatrix() in conjunction with remapCoordinateSystem() and getOrientation() method: The documentation says this "is usually more accurate". The problem is regardless of the delay I register with listener the compass goes crazy even when the device is stationary on flat surface.

Any suggestions for solving this problem will be greatly appreciated.

+1  A: 

It's the downside of compact parts made for phones. A $5000 IMU that we're using right now has an error of +/- 2 degrees and in that range it seems to go crazy as well.

Try stepping away from interference, metal surfaces, and see if it improves. If not, I hate to break the bad news, but that's the hardware.

Have you seen these?

http://developer.android.com/reference/android/hardware/SensorManager.html

http://groups.google.com/group/android-developers/browse_thread/thread/bbb0e8b97c673cf9/5c16bc2e49f6e972?lnk=raot

pinnacler
What I am trying to say is on the same phone (Nexus One) at the exact identical place on the kitchen table Snaptic Compass, a third party application from Android Market, is more accurate then my reading. I am wondering what trick Snaptic is using to get more accurate and reliable reading.
mob1lejunkie
See links I added to answer.
pinnacler
After poking around in Snaptic Compass settings I noticed it uses true north whereas I was using magnetic north. Now that I also use true north my application and Snaptic Compass have same reading. Of course reading isn't perfect but that is due to Nexus One hardware not a fault of my compass implementation.pinnacler thanks for your help!
mob1lejunkie
+2  A: 

Looks like mob1lejunkie has figured this out already, but just for future reference, let me mention that the issue here is magnetic declination (the difference between magnetic north and true north). You can try out an online model from NOAA to get a sense for what the difference is in your part of the world.

Android includes a model called GeomagneticField that can be used to compute the approximate declination given a latitude, longitude, and altitude. So, what I believe you need to do to compute true north is read out the azimuth value from Sensor.TYPE_ORIENTATION and then add to that GeomagneticField.getDeclination().

Drew Dara-Abrams
Yes this was exactly the issue.
mob1lejunkie