kriswiner / LSM9DS1

ST's new smaller, lower-power 9-axis motion sensor
40 stars 28 forks source link

Magnetometer Calibration #9

Closed dmamalis closed 6 years ago

dmamalis commented 6 years ago

@kriswiner i have been using your code to make an ecompass and I have had a few problems which I am trying to pin down. Seeing issues on other repos of yours I decided to put some more effort on calibrating the magnetometer before posting.

According to my results, unless I am doing something terribly wrong, the magcal algorithm seems to be inadequate.

First I run it multiple times and found out that the magBias results are completely different. Then I plotted some experiments to make this a bit more concise. In the next screenshots you can see three views of the same experiment (mx, my, mz being printed)

screenshot from 2017-12-20 23-21-00 screenshot from 2017-12-20 23-20-39 screenshot from 2017-12-20 23-20-22

It looks like there is need for both soft and hard iron calibration.

kriswiner commented 6 years ago

Yes, and the algorithm described here https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration does a pretty good job of both, you might have to collect data long enough to get a good sampling of the response surface. You are moving the sensor to sample the entire 3D sphere during the calibration, aren't you?

If you just leave the sensor flat on a table during the calibration, you aren't doing it right...

On Wed, Dec 20, 2017 at 1:32 PM, dmamalis notifications@github.com wrote:

@kriswiner https://github.com/kriswiner i have been using your code to make an ecompass and I have had a few problems which I am trying to pin down. Seeing issues on other repos of yours I decided to put some more effort on calibrating the magnetometer before posting.

According to my results, unless I am doing something terribly wrong, the magcal algorithm seems to be inadequate.

First I run it multiple times and found out that the magBias results are completely different. Then I plotted some experiments to make this a bit more concise. In the next screenshots you can see three views of the same experiment.

[image: screenshot from 2017-12-20 23-21-00] https://user-images.githubusercontent.com/5211553/34229620-a6aa83ec-e5dd-11e7-91a0-529e5e26f512.png [image: screenshot from 2017-12-20 23-20-39] https://user-images.githubusercontent.com/5211553/34229621-a6cc9496-e5dd-11e7-8bf7-1e8fb937c8bb.png [image: screenshot from 2017-12-20 23-20-22] https://user-images.githubusercontent.com/5211553/34229622-a6f025aa-e5dd-11e7-8e1a-5b85c79f4dbe.png

It looks like there is need for both soft and hard iron calibration.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM9DS1/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qof7gDvZrG_83wV92UrUgDU0BgURks5tCXzygaJpZM4RI_Sl .

dmamalis commented 6 years ago

That was a quick reply! Thank you.

I also used the MotionCalc calibration tool to visualize data and I realized that the previous screenshots MUST be wrong, at least with regards to the soft iron issue. I am guessing my gnuplot script is faulty.

Here is the MotionCalc screenshot with shows much better soft iron results screenshot from 2017-12-21 00-26-24

No I am definitely not leaving it flat but I guess a few more samples might be a better solution.

Last but not least, could you please explain to me why the magBias is commented out in these lines? https://github.com/kriswiner/LSM9DS1/blob/master/LSM9DS1_MS5611_BasicAHRS_t3.ino#L437

kriswiner commented 6 years ago

Because this sketch is using the mag offset bias registers internal to the LSM9DS1:

//write biases to accelerometermagnetometer offset registers as counts); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_X_REG_L_M, (int16_t) mag_bias[0] & 0xFF); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_X_REG_H_M, ((int16_t)mag_bias[0]

8) & 0xFF); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_Y_REG_L_M, (int16_t) mag_bias[1] & 0xFF); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_Y_REG_H_M, ((int16_t)mag_bias[1] 8) & 0xFF); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_Z_REG_L_M, (int16_t) mag_bias[2] & 0xFF); writeByte(LSM9DS1M_ADDRESS, LSM9DS1M_OFFSET_Z_REG_H_M, ((int16_t)mag_bias[2] 8) & 0xFF);

On Wed, Dec 20, 2017 at 2:33 PM, dmamalis notifications@github.com wrote:

That was a quick reply! Thank you.

I also used the MotionCalc calibration tool to visualize data and I realized that the previous screenshots MUST be wrong, at least with regards to the soft iron issue. I am guessing my gnuplot script is faulty.

Here is the MotionCalc screenshot with shows much better soft iron results [image: screenshot from 2017-12-21 00-26-24] https://user-images.githubusercontent.com/5211553/34231781-0b411188-e5e6-11e7-8a48-791f9d233b51.png

No I am definitely not leaving it flat but I guess a few more samples might be a better solution.

Last but not least, could you please explain to me why the magBias is commented out in these lines? https://github.com/kriswiner/LSM9DS1/blob/master/LSM9DS1_ MS5611_BasicAHRS_t3.ino#L437

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM9DS1/issues/9#issuecomment-353202341, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qmz_QfeoiRVFr2pdQB_g6J9C0XRBks5tCYsvgaJpZM4RI_Sl .

dmamalis commented 6 years ago

I changed the samples to 512 to give some extra data and the calibration is much better now. I consider this closed. Thank you.