![]() ![]() You can then use the X, Y, and Z readings to compute the location of "north" relative to whichever way you're pointing (keeping in mind that "north" changes as much as 30 degrees depending where on earth you are (called declination - see ), and that it's not horizontal to the ground either (confusingly, called "inclination" - see ) You first need calibration (either using the device calibration method, or, by rotating it in a complete circle to ascertain the full field strengths). (due to the vehicle's pitch and roll), see Tails86's answer for a ![]() Interested in the true (rather than magnetic) heading.Įdit: All this assumes the XY plane is horizontal. Obviously, the magnetic declination has to be added if one is the vehicle is heading east (90° magnetic heading) when the horizontalĬomponent of the magnetic field is along +yįrom here, it follows that the vehicle heading is heading = atan2(y, x) * 180 / M_PI.the vehicle is heading north (0° magnetic heading) when the horizontalĬomponent of the magnetic field is along +x.That the x axis of the magnetometer points forward and the y axis points The magnetometer has been mounted relative to the vehicle. It is likely that the OP wants instead to know the This formula gives the direction of the (x, y) vector counted clockwiseįrom the y axis. Simplified into az = atan2(x, y) * 180 / M_PI Now, since atan(y/x) = π/2 − atan(x/y), the formula above can be Thus, the correctįormula is az = 90 - atan2(y, x) * 180 / M_PI It is a very standardįunction of the C library and is called atan2(). The arctangent, yielding results in (-π, π] instead ofįortunately, such function already exists. ![]() That would be essentially a two-argument, “quadrant-aware” version of The formula could be fixed by replacing atan(y/x) by a function that Words, it cannot differentiate between north-east and south-west. It gives the same azimuth for x = y = 1 and for x = y = −1. However, it cannot work as is for two reasons: The answer given by Dave X, namely az=90-atan(y/x)*180/pi ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |