Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magnetometer calibration expected result could not achieved #41

Open
DavidKric opened this issue May 6, 2019 · 1 comment
Open

Magnetometer calibration expected result could not achieved #41

DavidKric opened this issue May 6, 2019 · 1 comment

Comments

@DavidKric
Copy link

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:
raw_data

plotting the values after hard iron offset removal:
after_hard_iron_removal

plotting the values after hard iron offset removal and soft iron removal:
fully_calibrated

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

@kriswiner
Copy link
Owner

kriswiner commented May 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants