# kar_ee

## Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
• Author
Posts
• #18281
kar_ee
Participant

I see. Thank you for your confirmation.

Is the yaw measurement equivalent to the heading measurement from the magnetometer provided in the code?

If using it on a stationary device, is the heading measurement still usable or I do need to come up with the yaw measurement by using gyro and magnetometer?

#18278
kar_ee
Participant

Hi Richard,

I have questions about the magnetometer calibration in hard and soft iron interference. In the code of compass_tutorial04.c for the heading formula uses

float heading = 180 * atan2(magRaw[1],magRaw[0])/M_PI;

but after calibration and add my blue text output (magX,Y,Zmax and magX,Y,Zmin) to compass_tutorial03.c, the heading formula in the tutorial03 code uses

float heading = 180 * atan2(scaledMag[1],scaledMag[0])/M_PI;

//Apply hard iron calibration
magRaw[0] -= (magXmin + magXmax) /2 ;
magRaw[1] -= (magYmin + magYmax) /2 ;
magRaw[2] -= (magZmin + magZmax) /2 ;

//Apply soft iron calibration
scaledMag[0] = (float)(magRaw[0] – magXmin) / (magXmax – magXmin) * 2 – 1;
scaledMag[1] = (float)(magRaw[1] – magYmin) / (magYmax – magYmin) * 2 – 1;
scaledMag[2] = (float)(magRaw[2] – magZmin) / (magZmax – magZmin) * 2 – 1;

My question is that if the calibration is to eliminate both hard and soft iron distortion, why the heading formula in tutorial03 and 04 are different and which one I should be using? I’m still a rookie to understand all these things and it will be great if anyone could help me to clarify my confusion.

Thank you.

Viewing 2 posts - 1 through 2 (of 2 total)