Heading magnetometer HMC5883L, tilted.

Hi! I am using I2Cdevlib to interface with both an MPU6050 and HMC5883L (autopilot sometime in the future). The library is really great, but there is a problem. Whenever I want to calculate my heading from the magnetometer I don't know how unless the sensor is close to flat. Is there a way I can calculate the heading when the sensor is not flat on the ground? Since I want to make an autopilot for an airplane I can count on it being level all the time. Tilting the magnetometer with the regular algorithm running gives huuuge errors.

Any help is greatly appriciated!


so u'll need accelerometer info in addition.. to tell orientation. and of course: u need to know how the magnetic field is orientated at your location.

This document explains in great detail how to use an accelerometer+magnetometer to create a tilt-compensated compass: http://cache.freescale.com/files/sensors/doc/app_note/AN4248.pdf There are simpler approaches than those described, though.