Problem with tilt compensation

Hey all,

I'm very happy to join DiyDrones community
(Sorry for my bad english)

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

if (heading < 0)
heading += 2*M_PI;

if (heading > 2*M_PI)
heading -= 2*M_PI;

return heading * toDeg;

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 cosRoll = cos(rollRads);
float sinRoll = sin(rollRads);
float cosPitch = cos(pitchRads);
float sinPitch = sin(pitchRads);

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

float heading = atan2(Yh, Xh);

if (heading < 0) {
heading += (2*M_PI);
}

if (heading > M_PI) {
heading -= (2*M_PI);
}

return heading * toDeg;

Video:

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

Thanks for your help !!

Views: 1783

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

Groups

45 members

1472 members

282 members

470 members

• 3D Models

57 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

© 2019   Created by Chris Anderson.   Powered by