Magnetometer and gyro fusion

Hi everyone,

I'm building a drone that will be radio controlled and hopefully one day semi-autonomous.

I am using an MPU6050 for attitude measurement and PIDs for attitude control.

The heading of the vehicle is controlled by the z-gyro, which obviously drifts over time as there is nothing to reference it against.

I am using a complementary filter for pitch and roll measurements fusing the gyro and accelerometer values which works very well.

My question is; is there a similar fusion that can be performed in connecting the gyro heading to the reading from a magnetometer to remove the gyro drift over time.

My initial gut feel was fusing the gyro rate with the differential of the magnetometer reading so they are both in angular velocity, similar to the complementary filter used in angle measuring, and then have a PID to compare the current angle rate with a desired value. So when an RC yaw command is sent, it will change the desired yaw rate and the PID will do the rest. Sound feasible or is there a better way to go about it? Thanks.

Look at multiwii.com. It is (IMO) the best and simplest arduino-base software for multirotors.

I am aware of multiwii, but I have Already written the software for it, and fusing the Z-gyro to a magnetometer would just be a small addition so was hoping to write it myself rather than use a ready made solution.

All I do is use multiwii. I am not so good with the actual code :slight_smile:

The best currently available open source software for IMU navigational fusion is the Arduino-compatible RTIMULib. It supports a number of different sensors, but you will have to take a look at the settings to see if yours are included.

My experience implementing it is briefly documented here.