Skip to content

Instantly share code, notes, and snippets.

View ViennaMike's full-sized avatar

Mike McGurrin ViennaMike

View GitHub Profile
@berikv
berikv / heading.py
Last active May 6, 2018 21:24 — forked from timtrueman/heading.py
- Fix wrap to allow for bigger angles - Replace the hardcoded declination correction with an argument
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.