I am trying to calibrate the magnetometer of a MPU9250(9255 actually) connected to a arduino nano.
I use the ellipsoid fitting method to calibrate the MPU9250. The calibrated magenometer values form a sphere around the origin with radius = local magnetic field intensity as expected. The plot of magnetometer(calibrated) x vs y, x vs z & y vs z are all nearly circular. The images of the same are attached at the end.
Even after the ellipsoidal correction, the magnetic field values seem to be un-explainable.
If I point any axis down towards gravity and then point in the reverse direction I am supposed to get a reversal of sign for the magnetic field intensity along that axis. However it seems way off from expected reversal.
I permute the x, y , z axes marked on the board to various combinations of north, east, south, west up and down.
mx, my, mz are the magnetic field values along the corresponding axes after calibration.. only y axis readings seemed to reverse sign with reversal of direction. x, z dont follow this behavior.
Also some components seem to reach 550mG even though the magnitude of the magnetic field intensity at my location(Bangalore) is 413.98 mG.
| x dir | y dir | z dir | mx | my | mz |
N W U -170 -95 550
S E U 325 60 -100
E N U 26 400 240
W S U 120 -440 190
U E N -320 15 -340
D W N -390 -15 -220
W U N -382 -75 -250
E D N -350 65 -300
U W S 360 -75 225
W N D -60 430 -15
U S E 40 -410 20
D S W 5 -440 150
The magnetic field data also seem noisy even when the IMU is stationary placed on a flat table.
My connection
9255 breakout board ----- Arduino uno
Vdd ----------- 5V
Gnd ----------- arduino gnd
SDA ----------- A4
SCL-----------A5
INT----------- 2
FSYNC ----------- GND
NCS ----------- 3.3V
I grab the raw magnetometer values(mx, my, mz) using kriswiners code and apply the ellipsoidal correction to the same
mx = (float)magCount[0]mResmagCalibration[0];
my = (float)magCount[1]mResmagCalibration[1];
mz = (float)magCount[2]mResmagCalibration[2];
The ellipsoidal correction looks correct from the spherical shape of the 3D polt of calibrated mx, my, mz.
The rotation and center of the ellipse are found once the ellipse fitting has been done.
Let the equation of the ellipse be:
v1x^2+v2y^2 + v3y2+2v4xy +2v5xz +2v6yz + 2v7x + 2v8y +2v9*z +v10=0; generic ellipse
which is equivalent to (x-o)'(Ae)(x-o)=1, o is the center of the ellipse
Ae=[v1 v4 v5;
v4 v2 v6;
v5 v6 v3]
o = - (inv(Ae))*[v7;v8;v9]
Now Ae =R'DR where R is the rotation that needs to be applied to a standard ellipse x^2/a^2 +y^2/b^2 +z^2/c^2 =1
to create a generlized ellipse.
we find R & D using SVD of Ae
RdR' = svd(Ae) giving the rotation matrix R.
To convert the generic ellipse to the standard form we first apply the inverse translation corresponding to o.
Then we apply the inverse rotation corresponding to R. The axes of the standard ellipse are used to determine the reverse scaling needed to map the ellipse to a sphere.
X' = scaling * Inverse_Rotation *(X-o)
Questions
- Why are the magnetometer values not reversing values for reversal of direction for all axes
- Why are the magnetometer values very noisy?
- Why does the maximum magnitude of the mz reach 550 even though I have set the manetic field intensity to be 413.9 and the sphere fitted is of the same radius?