Home › Forums › Forums › General discussion › Yaw measurement with gyro and magnetometer › Reply To: Yaw measurement with gyro and magnetometer
Hi Richard,
Thank you so much for your reply.
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
//Compute heading
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
//Compute heading
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.