MultiWiii Yaw Drift

Hi, I’m currently trying to make a flight controller using an adapted code for Multiwii by electronoobs. This code is modified for the controller to directly receive data from an NRF24l01 module without a receiver module. I am using an Arduino Nano, NRF24l01 and an MPU6050 module. I set up the controller on a breadboard to test the gyro and transmission through the MultiWii application and all seems to be working well except the yaw. In the application, the quadcopter is shifting its yaw direction by 1 degree every second or so and I have no idea why. I had also calibrated the accelerometer and yields the same result.

I had uploaded the original version of the code that uses an external receiver module, and it had no problem at all… meaning that the problem lies within the code that was modified.

I tried copying the IMU code of the original and pasting it into the modified version but it would seem that I needed to delete multiple other codes which might make matters worse… Can someone guide me through on what to do?

IMU.cpp (11.4 KB)

IMU.h (160 Bytes)

An external reference is required for a stable yaw value. Magnetometers (electronic compasses) are popular for that purpose, but the MPU6050 does not have one. 9DOF sensors do.

Hi, thank you for your reply. If the MPU6050 does not have a magnetometer, that would mean that all sketches would have the same yaw drift problem. However, in this case the original source code was working fine and directions were all stable. Which leads me to think that the problem lies within the codes however I cannot seem to pinpoint the problem myself as I am not an expert in coding.

Some sketches (including the DMP firmware built into the MPU6050) have better algorithms for estimating and subtracting the gyro offsets, so the result in yaw is more stable. But it still drifts, just much more slowly. The accelerometer data corrects for pitch and roll drift, using the known direction of Down.

Your problematic sketch evidently makes a poor estimate of yaw gyro drift, or perhaps none at all. It is impossible to tell, because your upload consists of just a few useless comments.

Of course, without a magnetometer or other external reference, it is impossible to have an absolute yaw value, with yaw = 0 degrees traditionally being either true or magnetic North.

Gyro drift is temperature dependent, so raise the temperature a few degrees and print out the raw gyro rate values to see the effect.

Thank you so much! Turns out my blockhead had got it wrong all the time, the original code did not even have yaw! Okay looks like its time to purchase a magnetometer.

I recommend the MPU9250 and the Mahoney algorithm or RTImulib and any of the compatible sensors, for absolute orientation angles.