Calibration of Compass Module

@ VB-Daniel

There are a number of factors affecting the accuracy of the compass module, depending on application requirements:

  1. Sensor linearity
  2. Magnetic offsets (soft and hard iron)
  3. Magnetic declination.

1 and 2 must be dealt with to achieve the 2 degree accuracy.
3 must be dealt with where you need to run calculations against, say, a GPS position (anytime you care about grid north).
If you wanted, for example, to just implement a heading hold autopilot, you don’t really care about declination. If you need to calculate a heading based on your current GPS position then you do care about declination.
The rate of change of declination is actually quite slow unless you’re trying to do really accurate navigation, in which case you are using the wrong sensor :slight_smile:

Unfortunately, the only way I know to work out declination with a cheap GPS is a table lookup.

@ KiwiSaner, how many points did you check? When I tested in circuit I got very different results to when I tested initially. I tricked myself that it was reasonably accurate because I happened to hit 4 points where it wasn’t too far out.

There is a calibration function in the sensor, but I couldn’t get it to work reliably (didn’t have enough time). It applies a known field to the sensor and lets you calibrate for some specific errors.

[quote=“Byron”]
unless you’re trying to do really accurate navigation, in which case you are using the wrong sensor[/quote]
I share your opinion but what do you want do?

  1. Navigation is a very dynamic process. wind and/or flow influence the position so you can’t follow the calculated course. You have to calculate the position dynamically and determine a new course.
  2. If you determine your position with gps you maybe get a position with 50m accurate.
    this cause a angle error.
    so my question is how long is the way between the measurement of the positions. what is the max angel error cause by the position accurate. Are this error and the sensor accurate bigger then the magnetic declination you can ignore it. ??

@ Byron - I must admit that I do seem to get varying degrees of accuracy each time I play with the compass.

And I would like to add a fourth aspect that also affects the accuracy . And that is that the tilt orientation of the compass module plays a significant role as well. If you tilt is slightly upward or downward or tilt it slightly left or right and the reading changes significantly. This is probably understandable as the compass reading takes all three axis into consideration when calculating a bearing.

I’m starting to think one will just have to accept that a digital compass module is quite a complex device that are influenced by many things. It can be quite accurate if used in a stationary implementation, but if you want to use it in a portable device or a vehicle, then it is quite difficult to guarantee its accuracy. One will just have to design around those constraints.

I know nothing about the compass module, but reading KiwiSaner’s response regarding the tilt reminded my of a tutorial I read sometime ago that I thought might be of interest here.

https://web.archive.org/web/20130624074336/http://www.loveelectronics.co.uk/Tutorials/13/tilt-compensated-compass-arduino-tutorial

1 Like

@ taylorza - Thank you very much! Very interesting and applicable article. I was considering trying to use a accelerometer to compensate for tilt, but my maths is so rusted. But that article shows all the maths and algorithms. It should be easy to port into my own project.

Hi,
i can’t found System.Math.Atan2() in my libs!
thx for any hlp

It should be inside mscorlib.dll assembly.

1 Like

@ iamin - Thx, found it (wrong framwork 4.1).