Compass calibration - I try again with Magneto

Hi everyone, today I decided to calibrate my compass again. And I wanted to use the Magneto program from @jremington

Here are my steps:

  1. I collected raw data for the magnetometer and accelerometer. I modified the program a little and collected them all at once. I don't know if I could have done that ??
compass.read();
float Xm_print, Ym_print, Zm_print, Xa_print, Ya_print, Za_print;



Xm_print = compass.m.x  ; // Gain X [LSB/Gauss] for selected sensor input field range (1.3 in these case)
Ym_print = compass.m.y; // Gain Y [LSB/Gauss] for selected sensor input field range
Zm_print = compass.m.z;  // Gain Z [LSB/Gauss] for selected sensor input field range


Xa_print = compass.a.x  ; // Gain X [LSB/Gauss] for selected sensor input field range (1.3 in these case)
Ya_print = compass.a.y; // Gain Y [LSB/Gauss] for selected sensor input field range
Za_print = compass.a.z;


Serial.print(int(Xm_print)); Serial.print(","); Serial.print(int(Ym_print)); Serial.print(","); Serial.print(int(Zm_print)); Serial.print("|");Serial.print(int(Xa_print)); Serial.print(","); Serial.print(int(Ya_print)); Serial.print(","); Serial.println(int(Za_print));
delay(25);

Attached are files for mag.csv and acc.csv

  1. I pass raw data through magneto for mag and acc:

Average magnitude (default Hm) and sigma of 8106 vectors = 3319.0, 724.6

Reject outliers? (0 or d, reject if > d*sigma from mean) 0
Rejection level selected: 0.0

8106 measurements processed, expected 8106

Expected norm of local field vector Hm? (Enter 0 for default 3319.0) 3319

Set Hm = 3319.0

Combined bias vector B:
222.57 219.03 -1146.96

Correction matrix Ainv, using Hm= 3319.0:
1.12102 0.00030 -0.00190
0.00030 1.11717 0.02254
-0.00190 0.02254 1.08653

Where Hcalc = Ainv*(H-B)

Code initialization statements...

float B[3]
{ 222.57, 219.03,-1146.96};

float Ainv[3][3]
{{ 1.12102, 0.00030, -0.00190},
{ 0.00030, 1.11717, 0.02254},
{ -0.00190, 0.02254, 1.08653}};
output filename for corrected values (csv)

For acc:

Average magnitude (default Hm) and sigma of 8106 vectors = 3319.0, 724.6

Reject outliers? (0 or d, reject if > d*sigma from mean) 0
Rejection level selected: 0.0

8106 measurements processed, expected 8106

Expected norm of local field vector Hm? (Enter 0 for default 3319.0) 1000

Set Hm = 1000.0

Combined bias vector B:
222.57 219.03 -1146.96

Correction matrix Ainv, using Hm= 1000.0:
0.33776 0.00009 -0.00057
0.00009 0.33660 0.00679
-0.00057 0.00679 0.32737

Where Hcalc = Ainv*(H-B)

Code initialization statements...

float B[3]
{ 222.57, 219.03,-1146.96};

float Ainv[3][3]
{{ 0.33776, 0.00009, -0.00057},
{ 0.00009, 0.33660, 0.00679},
{ -0.00057, 0.00679, 0.32737}};
output filename for corrected values (csv)

  1. Now I am entering data for the mag into the plot program
# Define calibration parameters
A = np.array(   [[1.12102,  0.00030, -0.00190],
                [0.00030,  1.11717,  0.02254],
                [-0.00190,  0.02254,  1.08653]])
b = np.array([222.57,  219.03, -1146.96])

And I get a graph like this:

magneto1_4.zip (20,5 KB)

Am I doing everything properly up to this point?

I want to ultimately use this roll compensation sketch:

Do I have to change the signs to the opposite by pasting them from the magneto?
float A_B[3] {....};
float M_B[3] {....};

Because I read somewhere that I should change the signs, but I don't know if it is so ...

Thank you in advance for your help in the difficult topic of compass calibration :wink:

Magneto (not written by me) reads only three columns of raw data. In the two passes you did, you processed the same data set twice.

Separate the raw magnetometer and accelerometer data into two .csv files and process them individually.

1 Like

I have processed the data by Magneto(2 point in my post - I wrote down the steps I was taking one by one), the only thing I am not sure about is the value I should give with the data from the accelerometer


`Average magnitude (default Hm) and sigma of 8106 vectors = 3319.0, 724.6

Reject outliers? (0 or d, reject if > d*sigma from mean) 0
Rejection level selected: 0.0

8106 measurements processed, expected 8106

Expected norm of local field vector Hm? (Enter 0 for default 3319.0) 0`

Leave the default value ??

Second question, can I paste the received values directly into your script or do I have to change the + - signs to the opposite?

You can use the default value for Hm for both the magnetometer and accelerometer. They will be very different.

Do not change any signs.

1 Like

Thank you, that's what I meant;) maybe it will be useful to someone;)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.