Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calibration of magnetometer doesn't give expected results

I want to have a "compass heading" (I want to know the angle upon the north) using a magnetometer. I have seen on several tutorials that first, I need to calibrate it. When I looked up on how to do it I saw graphics comparisons of magnetometer value with and without calibration.

Here are the links I used : link_one and link_two

Both links shows that an uncalibrated magnetometer should display several clusters on the graph as bellow :

This is the graph that I should have for an uncalibrated magnetometer

And calibrated mangnetometer should have both 3-axis on the same point around zero like this :

This is the graph that I should have after the calibration


I am using the Adafruit LSM9DS1. I tried to get the same graphics with the following python code :

def save_mag_values():
    f = open("magnetometer.csv","w")
    for i in range(10000):
        value = sensor.magnetic
        f.write(",".join(map(str,value)))
        f.write("\n")

Then I use the following gnuplot command to print :

gnuplot> plot "magnetometer.csv" using 1:2 title "XY" pointsize 2 pointtype 7, \
              "magnetometer.csv" using 1:3 title "XZ" pointsize 2 pointtype 7, \
              "magnetometer.csv" using 2:3 title "YZ" pointsize 2 pointtype 7

As it's written in the tutorial I just slowly move the sensor and after 1 min I print the values. Here is what I have for the uncalibrated magnetometer : My graph of non calibrated magnetometer

As you can see, the global shape is not a circle and I don't know why. I tried to calibrate it and here is what I have :

This is my graph with calibration

Can anyone tell me what I did wrong and why can't I have "circle shape" values like it should be ? Or Does the shape have to be perfect circle like I see on tutorials or mine are fine ? Thanks

like image 548
MelKoutch Avatar asked Nov 06 '22 19:11

MelKoutch


1 Answers

If your magnetometer is working (not magnetically damaged) and if you capture readings by rotating magnetometer 360 degrees along 3 axes, then your plot should show something like this(worst case scenario).

enter image description here

In ideal case, readings should be in 3 concentric circles overlapping in the same boundary.

In practical cases, due to soft and hard iron biases, surrounding magnetic material influences, readings will become elliptical and their centers will shift away as show in above figure.

Calibration simply brings them to common center and make elliptical readings circular.

Couple of years back, I have ordered several magnetometers. I spent a lot of time debugging code and later found that all of them were damaged during transit. I also wrote a blog post regarding calibration of magnetometer.

like image 178
Pandikunta Anand Reddy Avatar answered Nov 15 '22 11:11

Pandikunta Anand Reddy