Magnetometer calibration expected result could not achieved
Opened this issue · 1 comments
Hey Kris,
First of all, many thanks for sharing your work and knowledge about the IMU sesnor fusion.
i'm hoping to get your advice about an issue i'm dealing when calibration the mpu9250 magnetometer.
As i'm developing an application based on the MPU9250 i used your magnetometer calibration routine as shown and explained here:
https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration
my Issue is that i cant meet the expected result after calibrating the magnetometer data, i'm getting ellipsoid centered around 0,0 (photos attached).
i read here in some issue comments about the importance of the rotation of the sensor while collecting the data. i used tera-term to collect the mag adc values, and then preforming the calibration on the recorded data. i collected the data very carefully and kept rotating the sensor in sphere 3D shape, steady as i can.
the result are:
plotting the ADC values as is:
plotting the values after hard iron offset removal:
plotting the values after hard iron offset removal and soft iron removal:
as i get nice ellipses i suspect that the soft iron offset is not handled well.
the code used to find the scale value for the soft iron calibration:
double temp_scale[3] = {0};
mag_scale[0] = (mag_max[0] - mag_min[0])/2;
mag_scale[1] = (mag_max[1] - mag_min[1])/2;
mag_scale[2] = (mag_max[2] - mag_min[2])/2;
qDebug() << "Mag bias applied on all vectors done!";
double avg_rad = mag_scale[0] + mag_scale[1] + mag_scale[2];
avg_rad /= 3.0;
temp_scale[0] = avg_rad/mag_scale[0];
temp_scale[1] = avg_rad/mag_scale[1];
temp_scale[2] = avg_rad/mag_scale[2];
for(ii = 0; ii < m_x.size() ; ii++)
{
// x axis
m_x[ii] *= temp_scale[0];
}
for(ii = 0; ii < m_y.size() ; ii++)
{
// y axis
m_y[ii] *= temp_scale[1];
}
for(ii = 0; ii < m_z.size() ; ii++)
{
// z axis
m_z[ii] *= temp_scale[2];
}
Many Thanks in advance!
David