MPU6050 icon indicating copy to clipboard operation
MPU6050 copied to clipboard

Calibration values question

Open jc508 opened this issue 8 years ago • 9 comments

Hi, Thanks for this but I hope you have time for a couple of questions about the code... I am trying to convert this for use on a QMC5883L chip (sometimes you just have to work with what arrives). This says its 16bit but does not actually say anywhere what unit-of-measure the registers return, just that they are 16 bit integer from -32768 to 32767. It also does not have any factory calibration nor scale - or none that are published anyway.

so for the lines of code like ... dest1[0] = (float) mag_bias[0] * mRes * MPU9250magCalibration[0]; mx = (float)magCount[0]mResmagCalibration[0] - magBias[0]; I have eliminated MPU9250magCalibration

In the main program I have also found you have defined mres for 16bit values as....... mRes = 10.*4912./32760.0

Can you please explain the magic of these values ?

My original sketch had simply float heading = (atan2((float)y,(float)x)); headingDegrees = (heading * C_rad_to_deg); this mostly worked except for non-linear values < 50degrees - whereupon people tell me I have to calibrate the animal first !

I think I understand adjusting by the bias ie "- magBias[0]" and scaling ie mx *= magScale[0]; but the presence of mRes is escaping me.

Thanks in anticipation JC

jc508 avatar Nov 03 '17 02:11 jc508

mRes just converts the raw sensor values into something more interesting like milliGauss. 4912 Tesla full scale, 32768 full scale count 10 milliGauss per Tesla, or something like this. Look at the data sheet for similar:

https://aerocontent.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf

On Thu, Nov 2, 2017 at 7:44 PM, jc508 [email protected] wrote:

Hi, Thanks for this but I hope you have time for a couple of questions about the code... I am trying to convert this for use on a QMC5883L chip (sometimes you just have to work with what arrives). This says its 16bit but does not actually say anywhere what unit-of-measure the registers return, just that they are 16 bit integer from -32768 to 32767. It also does not have any factory calibration nor scale - or none that are published anyway.

so for the lines of code like ... dest1[0] = (float) mag_bias[0] * mRes * MPU9250magCalibration[0]; mx = (float)magCount[0]mResmagCalibration[0] - magBias[0]; I have eliminated MPU9250magCalibration

In the main program I have also found you have defined mres for 16bit values as....... mRes = 10.*4912./32760.0

Can you please explain the magic of these values ?

My original sketch had simply float heading = (atan2((float)y,(float)x)); headingDegrees = (heading * C_rad_to_deg); this mostly worked except for non-linear values < 50degrees - whereupon people tell me I have to calibrate the animal first !

I think I understand adjusting by the bias ie "- magBias[0]" and scaling ie mx *= magScale[0]; but the presence of mRes is escaping me.

Thanks in anticipation JC

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU6050/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsl85_wEPkOxvLhPzOVJFRzJIv0Cks5syn4IgaJpZM4QQmI7 .

kriswiner avatar Nov 03 '17 02:11 kriswiner

Hi there Kris, first off your Github page is a gold mine. Secondly, in this code `// Get hard iron correction mag_bias[0] = (mag_max[0] + mag_min[0])/2; // get average x mag bias in counts mag_bias[1] = (mag_max[1] + mag_min[1])/2; // get average y mag bias in counts mag_bias[2] = (mag_max[2] + mag_min[2])/2; // get average z mag bias in counts

dest1[0] = (float) mag_bias[0]MPU9250mResMPU9250magCalibration[0]; // save mag biases in G for main program dest1[1] = (float) mag_bias[1]MPU9250mResMPU9250magCalibration[1];
dest1[2] = (float) mag_bias[2]MPU9250mResMPU9250magCalibration[2]; `

You also use MPU9250magCalibration. What is this term for?

Thanks in advance

maopal avatar Feb 15 '21 19:02 maopal

That's the factory calibration of the AK8963C magnetometer. Perhaps poorly named.

On Mon, Feb 15, 2021 at 11:36 AM palemao [email protected] wrote:

Hi there Kris, first off your Github page is a gold mine. Secondly, in this code `// Get hard iron correction mag_bias[0] = (mag_max[0] + mag_min[0])/2; // get average x mag bias in counts mag_bias[1] = (mag_max[1] + mag_min[1])/2; // get average y mag bias in counts mag_bias[2] = (mag_max[2] + mag_min[2])/2; // get average z mag bias in counts

dest1[0] = (float) mag_bias[0]MPU9250mResMPU9250magCalibration[0]; // save mag biases in G for main program dest1[1] = (float) mag_bias[1]MPU9250mResMPU9250magCalibration[1]; dest1[2] = (float) mag_bias[2]MPU9250mResMPU9250magCalibration[2]; `

You also use MPU9250magCalibration. What is this term for?

Thanks in advance

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU6050/issues/19#issuecomment-779414909, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTDLKRUVHII44UTFPX2P2LS7FZVRANCNFSM4ECCMI5Q .

kriswiner avatar Feb 15 '21 19:02 kriswiner

Is that the same as the Sensitivity adjust values as shown in this picture?

If not how could I calculate/find this value? What value did you use?

Many thanks

IMG_20210215_221113115.jpg

maopal avatar Feb 15 '21 22:02 maopal

Yes.

On Mon, Feb 15, 2021 at 2:14 PM palemao [email protected] wrote:

Is that the same as the Sensitivity adjust values as shown in this picture?

If not how could I calculate/find this value? What value did you use?

Many thanks

[image: IMG_20210215_221113115.jpg] https://user-images.githubusercontent.com/74777355/107997486-c09cfe80-6fda-11eb-9dc3-730c75013aeb.jpg

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU6050/issues/19#issuecomment-779470827, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTDLKUREUH7IPI4LEP553DS7GMEHANCNFSM4ECCMI5Q .

kriswiner avatar Feb 15 '21 22:02 kriswiner

Hi Kris, other than accounting for soft-iron and hard-iron biases, is there any other calculation I need to do before inputting mag data into madwickquaternionupdate() function. Correcting for magnetic declination perhaps?

Thanks again

maopal avatar Feb 19 '21 20:02 maopal

Magnetic declination is accounted for after the filter when you change the quats into Euler angles. Then True North is AHRS North (i.e., yaw = 0) minus your declination.

On Fri, Feb 19, 2021 at 12:50 PM palemao [email protected] wrote:

Hi Kris, other than accounting for soft-iron and hard-iron biases, is there any other calculation I need to do before inputting mag data into madwickquaternionupdate() function. Correcting for magnetic declination perhaps?

Thanks again

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU6050/issues/19#issuecomment-782338835, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTDLKSHJMUZVZGI64V4JHLS73FHXANCNFSM4ECCMI5Q .

kriswiner avatar Feb 19 '21 21:02 kriswiner

I just came across this post where you mention accounting for declination in your response. "you have taken into account the local magnetic declination". https://github.com/kriswiner/MPU9250/issues/345

Just a bit confused now... thanks again

maopal avatar Feb 19 '21 22:02 maopal

a12 =   2.0f * (q[1] * q[2] + q[0] * q[3]);
a22 =   q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3];
a31 =   2.0f * (q[0] * q[1] + q[2] * q[3]);
a32 =   2.0f * (q[1] * q[3] - q[0] * q[2]);
a33 =   q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3];
pitch = -asinf(a32);
roll  = atan2f(a31, a33);
yaw   = atan2f(a12, a22);
pitch *= 180.0f / pi;

*yaw = 180.0f / pi; yaw += 13.8f; // Declination at Danville, California is 13 degrees 48 minutes and 47 seconds on 2014-04-04 if(yaw < 0) yaw += 360.0f; // Ensure yaw stays between 0 and 360 roll *= 180.0f / pi; lin_ax = ax + a31; lin_ay = ay + a32; lin_az = az - a33;

On Fri, Feb 19, 2021 at 2:07 PM palemao [email protected] wrote:

I just came across this post where you mention accounting for declination in your response. "you have taken into account the local magnetic declination". kriswiner/MPU9250#345 https://github.com/kriswiner/MPU9250/issues/345

Just a bit confused now... thanks again

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU6050/issues/19#issuecomment-782395378, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTDLKVLYX2S5UCGGTX6353S73OIZANCNFSM4ECCMI5Q .

kriswiner avatar Feb 19 '21 22:02 kriswiner