composate heading using mpu6050+HMC5883L

Hello there i'm working on a project, that i use 10 DOF mpu6050 /HMC5883L/BMP180.
i want to componsat th eror of the heading so i tried to use this formula

"m for the magnet field"

float   Yh = my * cos(pitch) - mz * sin(pitch);
float Xh = mx* cos(roll) + mz * sin(pitch) * sin(roll) + mz* (pitch) * sin(roll);
   heading = atan2(Yh, Xh);
      if (heading < 0) heading += 2 * M_PI;


i tried a lot of test but the composation stil not working properly 
here it is my test

when the heading is between 250 and 300 degrees.  the tilt composation works fine when i do a negative ROLL. but if a do a positive ROLL or positive  and negative PITCH it does'nt composate.

when the heading is on 0 degrees, the tilt composaton works fine when i do  a negative PITCH. but if a do a positive  PITCH or positive  and negative ROLL it does'nt composate.


is there something wrong with the formula 
please help 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…