0

Dear programmers/scripters/engineers/other people,

The problem: I'm currently developing an augmented reality application for an Android 3.2 tablet and having some issues with getting an accurate compass reading. I need to know exactly the (z) direction the tablet is facing, measured from the north. It doesn't matter if it's in degrees or radians.

What I currently have tried:

  1. I used the magnetometer and accelerometer to calculate the angle. It has one big disadvantage. If you rotate 90 degrees, the sensors will measure a larger or a smaller angle. Even when I'm in an open field far away from metal or any magnetic objects. Even the declination doesn't solve it.

  2. Using the gyroscope would be an option. I have tried to measure the rotating speed and store the measured units into a variable to know the exact view direction. There seems to be an factor that causes distortion though. I found out that fast rotations distort the accurate direction measurement. The gyro's drift wasn't that much troublesome. The application checks the other sensors for any movement. If none is detected, the gyro's rotation change won't be taken into account.

  3. The rotation vector works okay. It has some issues like the gyroscope. If you move slowly and stop at a suddenly moment, it will drift away for a few seconds. Another problem is that it will be inaccurate with quick rotations depending on the speed and how many turns you've made. (You don't want to know how my co-workers are looking at me when I'm swinging the tablet in all directions...)

  4. Sensor.Orientation, not much to say about. It is deprecated for some reason so I won't use it. A lot of examples on the internet are using this sensor and it's probably the same thing as the magnetic/accelerometer combination.

So I'm currently out of idea's. Could you help me with brain storming / solution solving? Thanks in advance, yours sincerely, Roland

  • EDIT 1: I am willing to provide the code I have tried.
Roland
  • 11
  • 1
  • 3
  • i think that option 1 is your first bet as this is the official way to get the device orientation. I understand your problem with that approach is jitter? You can tackle that with a low pass filter. Take the median or average of the last x values.. There are certainly other more sophisticated methods to deal with signal noise but this might be enough. – Renard Apr 10 '12 at 22:25
  • Thank you for your help! I have tried some filters indeed. I forgot to mention it. But I will try it again. But the main problem is more the accuracy. At least, the magnetometer could be up to 20 degrees wrong. That can't be solved with a filter, right? Or do you think otherwise? – Roland Apr 11 '12 at 06:54
  • such a large error might be due to bad calibration. During the development of my compass app it has helped me tremendously to compare this [app](https://play.google.com/store/apps/details?id=com.apksoftware.compass&hl=de) to mine and check if i was doing it right. – Renard Apr 11 '12 at 07:32
  • I have my doubts about that. I checked recently other compass applications but they seem to produce the same error rate as the magnetic field sensor. But is there a way to calibrate the sensor itself? I'll try to look at this again... – Roland Apr 11 '12 at 07:46
  • Well the sensors on phones are not very accurate to begin with. But you did the figure 8 motion thing holding the phone flat in front of you? – Renard Apr 11 '12 at 08:01
  • check [this](http://www.augmentedplanet.com/2010/04/mixare-video-explains-mobile-compass-accuracy-issues/) out – Renard Apr 11 '12 at 08:23
  • I will try it again. I'm not very confident in the calibration method I used. Thanks for all your help so far. :) – Roland Apr 11 '12 at 08:37
  • *Update: the video was remarkable how bad those magnetometers are. The calibration didn't have any effect either though... – Roland Apr 11 '12 at 12:42

1 Answers1

2

I'm summing up our comments:

  1. its clear from this video that the sensors on phones are not very accurate to begin with. Also interesting to read is this
  2. it its important that the user calibrates the sensors by doing a figure 8 motion holding the phone flat. An App can programmatically check if such a calibration is necessary and notify the user. See this question for details
  3. To eliminate jitter the values obtained from the sensors need to be filtered by a low pass filter of some kind. This has also been discussed on StackOverflow.
  4. The orientation obtained is not the true north. To obtain the true north one must use GeomagneticField
Community
  • 1
  • 1
Renard
  • 6,909
  • 2
  • 27
  • 23
  • 1. Yep and that is why I asked here for any other idea's how to get an accurate measurement. 2. Still doesn't change the accuracy. 3. Doesn't change an offset of 20 degrees even with calibration. :) 4. I calculated the declination based on the latitude/longitude/height and so on. That 'sadly' doesn't change it. – Roland Apr 11 '12 at 13:18
  • You simply cant increase the accuracy if the hardware is the problem. I've read (but lost the source) that -/+6 Degrees are normal. Do you read the 20 Degree offset on different devices? Have you checked that there are no metallic objects (laptop) nearby? – Renard Apr 11 '12 at 13:26
  • Yep, I'm in the open field. I've tested another (Android 3.2) device which gives other results though... Seems to be more accurate and a different offset. But still I have the feeling that it isn't accurate enough. Maybe I'm going to mix those sensors again. – Roland Apr 11 '12 at 14:38
  • i dont think that you will get good results out of the sensors :-( see this [post](http://stackoverflow.com/questions/6256256/android-compass-seems-unreliable) – Renard Apr 11 '12 at 15:19
  • Same here... But I have another idea! The gyroscope seems to be accurate enough depending on the acceleration. I will try it out today and let you know if it works. :) – Roland Apr 12 '12 at 06:50
  • I finally got the answer! For the best azimuth: Use the magnetic field sensor and compensate it for hard and soft iron effects. Link: http://www.memsense.com/index.php/technical-notes/menu-id-146.html. For pitch and roll compensation, just let the gyroscope take over the azimuth measurements. This way you will get a very accurate answer. It works quite well for augmented reality! I'm very suprised! – Roland Jun 20 '12 at 13:33