how to composate heading using mpu6050+HMC5883L

Hello there i'm working on a project, that i use 10 DOF mpu6050 /HMC5883L/BMP180. i used this code mpu_6050/hmc5883l

i'm searching on the internet to find the formula about the tilt composation so i find this formula

// tilt compensated magnetic sensor measurements
  float magxcomp = Magx*cos(Pitch)+Magz*sin(Pitch);
  float magycomp = Magx*sin(Roll)*sin(Pitch)+Magy*cos(Roll)-Magz*sin(Roll)*cos(Pitch);

problem is that the heading is not comosated. when i did a roll or a pitch the value of the heading change, so i want to fix this prblem, i want the value of heading stay correct event i did a pitch or a roll. thanks

is there something wrong with the formula ?? i'mo working on autonomous flight so i need the correct value of heading, please helpe

Here is the complete analysis. Take your pick! http://cache.freescale.com/files/sensors/doc/app_note/AN4248.pdf https://www.nxp.com/files/sensors/doc/app_note/AN3461.pdf

Of course, you must be certain that [u]your[/u] definition of pitch and roll is the same as used by the authors.

thanks but its to hard for me thios files :). i'm looking for the easiest way to do the composation

If this project is too hard, you'll either need to spend time learning the background material, or find another project.

i have to do this project because i will build an autonoumous flight, so i must do the tilt composation. could you help me please