How to use cal data from MagCal/Magneto into AHRS

The correction as implemented in the Pololu code is not the best, but it should work much better than what you described in your first post. You didn’t describe your procedures well enough to determine what might be wrong. However, the environment where you mounted the sensor might substantially distort the Earth’s magnetic field, in which case the calibration constants are wrong.

I suggest to redo the entire calibration procedure and double check every step.

[quote]1)I don’t have the lines of code you show in the MinIMU-9AHRS[/quote]The AHRS code calls the LSM303 library, which reads the magnetometer. I may have posted code from an older version of the LSM303 library. I just now looked at the Gibhub sources, which is what you should be using. There are some cosmetic differences in how the magnetometer is read.

[quote]Is this
m[0] = (int16_t)(block[0] | block[1] << 8);
m[1] = (int16_t)(block[2] | block[3] << 8);
m[2] = (int 6_t)(block[4] | block[5] << 8);
equal to this
Xc = M11 M12 M13 x Xnc - Bx = m[0] = Xc = m[Xc#]
Yc = M21 M22 M23 x Ync - By = m[1] = yc = m[Yc#]
Zc = M31 M32 M33 x Znc - Bz = m[2] = Zc = m[Zc#]
[/quote]
The first three lines just form three 16 bit integers from the raw magnetometer data (one measurement for each axis). I don’t understand what you mean by the next three.

To introduce the code needed for this correction you will have to modify the libraries in several places. This requires that you have the complete source code, are reasonably familiar with it and that your coding skills are up to the task. Are you familiar with how to write the code for matrix multiplication?

You might consider an alternative AHRS which for theoretical reasons should perform quite a bit better than the MiniIMU-9 AHRS. I described my experience in implementing it in this post: State of the art AHRS for $25