# Problem with tilt compensation

Hey all,

I'm very happy to join DiyDrones community

I'm working on my new project with a drone 3DR frame and 10DOF IMU (MPU6050, HMC5883, MS5611 http://www.drotek.fr/shop/en/home/62-imu-10dof-mpu6050-hmc5883-ms56...), 1 or 2 days per month for 3 years so moving very slowly between the IHM and the embedded code!

I using a MPU6050 and HMC5883 Magnetomter and chipkit pic32 Board !

If using a heading with only magnetometer with this code my yaw axis it's good (if don't move other axis):

My code:

float heading = atan2(mag.y, mag.x); // mag.x and mag.y it's raw value scaled ( raw * 0.92 )  1.3Ga

Video :

If add a tilt compensation with accelerometer my yaw axis, move with roll and pitch inclination

My code:

float rollRads = acc.x * toRad; // acc.x = acc angle calculate with acos( accX(G) ) converted to deg

float pitchRads = acc.y * toRad; // acc.y =  acc angle calculate with acos( accY(G) ) converted to deg

float Xh = mag.x * cosPitch + mag.y * sinRoll * sinPitch + mag.z * cosRoll * sinPitch;
float Yh = mag.y * cosRoll - mag.z * sinRoll;

}

}

Video:

My code is available on github (Check IMU.cpp):
https://github.com/marc-j/NeuroDrone-pic32

Views: 1804

### Replies to This Discussion

I found the problem after simulation, resolved by this calcul :

float Xh = (mag.x * cosRoll) + (mag.y * sinPitch * sinRoll) - (mag.z * cosPitch * sinRoll);
float Yh = (mag.y * cosPitch) - (mag.z * sinPitch);

1

2

3

4

5

6

7

8

9

10

## Groups

15 members

82 members

24 members

9 members

• ### ESPrtk -High quality RTK…

9 members

Season Two of the Trust Time Trial (T3) Contest
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here