This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrap(angle): | |
while angle > 2 * pi: | |
angle -= 2 * pi | |
while angle < 0: | |
angle += 2 * pi | |
return angle | |
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta, declinationRadians=0): | |
""" Takes in raw magnetometer values, pitch and roll and turns it into a tilt-compensated heading value ranging from -pi to pi (everything in this function should be in radians). | |
The correct value for declinationRadians can be found online: http://magnetic-declination.com/countries.php note that this value is in radians, not in degrees. |