Hello,
i've got a magnetometer and want to get yaw angle of reference point. For example : my magnetometer is pointet to North and the value is beetwen 0 (+-2) and 360 (+-2). If i rotate my magnetometer right or left the yaw value gets it's value proportional to the rotation ( rotating clockwise 30 degree, yaw value is 30 degree, rotating clockwise 390 degree, yaw value is 30), but if i try rotating otherwise values are getting crazy, the same problem is for another reference angle for example 60 , 180 , 250 degree.
My goal is to measure YAW angle. If i rotate clockwise my magnetometer the YAW value incresing proportional to the compass value. Otherwise the value decreasing proportional. Max angle :180 min angle :-180 for the YAW value.
Measuring yaw could hardly be simpler. If the compass is held level, with X and Y axes in the horizontal plane, and assuming magx and magy are the calibrated values (with offset and scale corrected):
yaw = 180.0*atan2(magy, magx)/PI - declination; //mag declination in degrees
yaw=0 when the X axis points to magnetic North. You may wish to change the sign of yaw, so that it increases clockwise from North to East, as is conventional.