Hi everyone, today I decided to calibrate my compass again. And I wanted to use the Magneto program from @jremington
Here are my steps:
- 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
- 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.08106 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.96Correction matrix Ainv, using Hm= 3319.0:
1.12102 0.00030 -0.00190
0.00030 1.11717 0.02254
-0.00190 0.02254 1.08653Where 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.08106 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.96Correction matrix Ainv, using Hm= 1000.0:
0.33776 0.00009 -0.00057
0.00009 0.33660 0.00679
-0.00057 0.00679 0.32737Where 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)
- 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 ![]()
