Home › Forums › Forums › General discussion › Yaw measurement with gyro and magnetometer
Tagged: Yaw
- This topic has 5 replies, 2 voices, and was last updated 4 days, 7 hours ago by Tracy Smith.
- AuthorPosts
- June 14, 2023 at 8:18 am #18271kar_eeParticipant
Hi there,
I couldn’t find any information for yaw measurement by BerryIMU in Ozzmaker webpage. Is there any tutorial with yaw measurement?
Thanks,
Kar
June 14, 2023 at 12:00 pm #18272richardpParticipantHi Kar
You need to use the compass (magnetometer) to measure yaw. follow the tutorials on this site, make sure you calibrate the compass and use the code which includes tilt compensation
Richard --OzzMaker.com --
June 20, 2023 at 1:26 am #18278kar_eeParticipantHi 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.
June 20, 2023 at 1:44 pm #18279richardpParticipantWhat you could do is just apply hard iron offset , this should be good enough.
You would only need to use the code below;
//Apply hard iron calibration magRaw[0] -= (magXmin + magXmax) /2 ; magRaw[1] -= (magYmin + magYmax) /2 ; magRaw[2] -= (magZmin + magZmax) /2 ; //Compute heading float heading = 180 * atan2(magRaw[1],magRaw[0])/M_PI;
Richard --OzzMaker.com --
June 21, 2023 at 7:03 am #18281kar_eeParticipantI 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?
June 21, 2023 at 3:09 pm #18283richardpParticipantYou should be able to use the heading Measurment only. When rotating along yaw, you can just work out the difference in heading values from start to finish to see how far you have rotated.
Richard --OzzMaker.com --
- AuthorPosts
- You must be logged in to reply to this topic.