After looking at a number of recent papers on magnetometer calibration, I have decided on the following path to improve the calibration of a custom compass under development.

It is based on the availability of a PC software tool called MagCal.exe, developed by the PLAN Research Group at the University of Calgary, Alberta, Canada.

First, here is how to get the software:

1. Go to their website: http://plan.geomatics.ucalgary.ca/

2. On their menu bar, select Research, then Publications

3. Type MagCal in the Search Criteria textbox, then click on the ‘Search’ button.

4. Right click on ‘Download Executable’, then pick ‘Save target as…’ in the pop-up menu

5. Save the MagCal.zip file on your machine

6. Unzip, and you are ready to go.

You can also download the PDF paper on which the software is based at the same location.

So what MagCal exactly does? As stated in the about box: “This code computes the calibration parameters of a tri-axis magnetometer”.

From an input file containing raw measurement of the magnetometer, it finds 12 calibration values that correct for a whole set of errors: bias, hard iron, scale factor, soft iron and misalignments. Note that you will have to invert a 3x3 matrix result (there are online tools for that). What they don’t tell is that the same software can also be used to calibrate the accelerometer for bias, scale factor AND misalignments.

Here is a rendering (using Google SketchUp) of the example raw data file provided with the MagCal software.

The whole idea is to first make this calibration on the completed compass in a magnetic clean environment (like an exterior isolated field).

The whole calibration procedure will be like this:

1. Record a set of static measurements (magnetometer and accelerometer) by positioning the compass in a large number of orientiations covering a whole sphere

2. Process the data in MagCal to find the calibration values (12 each for the magnetometer and the accelerometer)

3. Carefully position the compass assembly completely horizontal (use a precision level).

4. Record the accelerometer output at this position, to find the orientation of the accelerometer versus the whole compass assembly. This will be used to apply a final correction to the calibrated accelerometer values before applying the tilt compensation equations.

Note that once the compass will be installed in the boat, there may be additional hard and soft iron errors induced by the boat structure and equipment. These will be later identified with the help of the GPS, as shown in a previous post.

In Part 2 of this post, I present 'Magneto', a similar software tool which has some practical advantages compared to 'MagCal'.

Hi, probably our entry may be off topic but anyways, I have been surfing around your blog and it looks very professional. It’s obvious you know your topic and you appear fervent about it. I’m developing a fresh blog plus I’m struggling to make it look good, as well as offer the best quality content. I have learned much at your web site and also I anticipate alot more articles and will be coming back soon. Thanks you.

ReplyDeletehello!!!amazing post and excellent!is the source code of the algorithm for the calibration available for matlab!since i am most familiar with it!thanx :)

ReplyDeleteSee :

Deletehttps://sites.google.com/site/sailboatinstruments1/presentation

for a link to a Matlab implementation of the Li's

ellipsoid fitting algorithm. You will to complete with the calculation of the correction matrix as shown in:

https://sites.google.com/site/sailboatinstruments1/proof

thanx!when you say i have to complete you mean to do the last 5 steps?

Deletea i found it !!!just 2 last questions!!!!

Deletedouble hm;

double* A_1 = new double[3*3];

for(i = 0; i < 9; i++)

A_1[i] = SQ[i] * hm / hmb;

what does hm stands for?

and :

***Calculate A to permit comparison with MagCal***

what does the part of the code do here?calcualtes A-1?

i asked silly questions!i completed it!thanx a lot !!!this calibration technic offered me the only correct results :)!!!!

DeleteReally interesting subject, as I struggled with this for some time now with little luck. Ellipsoid fitting is not an easy task...

ReplyDeleteAnyway - in order to see what the output would be when applying the correction matrix on the data provided in your sample, I wrote a small program that applies the correction and plots the data.

However I didn't get the perfect sphere I had hoped for and wonder if I made something wrong.

I could publish the application and results here If I only knew how to attach files and pictures...

Thank you! This post is an excellent tutorial for calibrating magnometer such HMC-5883L sensor.

ReplyDeleteHi,I want to ask a question of the procedure 1,

ReplyDeleterecord a set of "static" measurement by positioning the compass in a large number of orientiations covering a whole sphere. How to record static measurement when position whole orientations to cover a whole sphere when rotate the compass? and how many sets should I record is enough?

In practice, I only rotate the compass around 3 mutually perpendicular axis, as this is enough to define an ellipsoid of measurements. Using 10 degrees steps for each measurement is quite enough. It is particularly important that the compass does not move during the accelerometer measurements, as any vibration will affect the results (hence the 'static' recommendation). I fix the compass to a wooden peg

Deleteleaning on a support to make the measurements.

Hi,Merlin

DeleteI've done lots of times,after the calibration seems very effective,but as time goes by(2~3hours) I found that magnetometer would become inaccurate even in the same environment,is that normal? Do I need to calibration maybe every couples of hours?

Definitely not normal if the environment has not changed.

DeleteI am in the office,so there are computers and steel inside the concrete skeleton,guess maybe the problem here.

DeleteHi Merlin, thanks for this great blogPost. I am trying to find the value for the Norm of the Earths Magnetic Field. Your link is a 404 but i tracked it down here: https://www.ngdc.noaa.gov/geomag-web/#igrfwmm

ReplyDeleteThe issue is that this outputs 8 fields, but none of them are called 'norm'.

# (1) Date in decimal years

# (2) Declination in decimal degrees

# (3) Inclination in decimal degrees

# (4) Horintensity in nanoTesla (nT)

# (5) Totalintensity in nanoTesla (nT)

# (6) Xcomponent in nanoTesla (nT)

# (7) Ycomponent in nanoTesla (nT)

# (8) Zcomponent in nanoTesla (nT)

What do you suggest i use as 'norm' for the MagCal input??

thx