mpu6050 and Motor vibrations

Hallo again,
first of all, i knew there are much topics like this and i serached and tried and tried …

I want to stabilize my quadcopter with arduino Due and MPU6050, bought from ebay,
http://www.ebay.de/itm/121126126397?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

I’m filtering the raw values with the complementary filter, but the motor vibrations are to strong, therefore i dont have good values to work with.
Should i change the dps from the Gyro? If yes, how can i do it?

``````#define ACCELEROMETER_SENSITIVITY 8192.0
#define GYROSCOPE_SENSITIVITY 65.536
#define M_PI 3.14159265359
#define dt 0.01

void ComplementaryFilter(short accData[3], short gyrData[3]){
float pitchAcc, rollAcc;

// Integrate the gyroscope data -> int(angularSpeed) = angle
pitch += ((float)gyrData[0] / GYROSCOPE_SENSITIVITY) * dt; // Angle around the X-axis
roll -= ((float)gyrData[1] / GYROSCOPE_SENSITIVITY) * dt;    // Angle around the Y-axis

// Compensate for drift with accelerometer data if !bullshit
// Sensitivity = -2 to 2 G at 16Bit -> 2G = 32768 && 0.5G = 8192
int forceMagnitudeApprox = abs(accData[0]) + abs(accData[1]) + abs(accData[2]);
if (forceMagnitudeApprox > 8192 && forceMagnitudeApprox < 32768)
{
// Turning around the X axis results in a vector on the Y-axis
pitchAcc = atan2f((float)accData[1], (float)accData[2]) * 180 / M_PI;
pitch = pitch * 0.99 + pitchAcc * 0.01;

// Turning around the Y axis results in a vector on the X-axis
rollAcc = atan2f((float)accData[0], (float)accData[2]) * 180 / M_PI;
roll = roll * 0.99 + rollAcc * 0.01;
}
}
``````

These are Outputs of my Code the Pitch value is drifting so much, why?
Its the same position.

Roll :0.71 Pitch :0.04 Speed Motor 2 :60 Speed Motor 4 :60

Roll :0.77 Pitch :0.08 Speed Motor 2 :60 Speed Motor 4 :60

Roll :0.86 Pitch :0.07 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.22 Pitch :0.02 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.66 Pitch :-0.13 Speed Motor 2 :60 Speed Motor 4 :60

Roll :2.08 Pitch :0.06 Speed Motor 2 :60 Speed Motor 4 :60

Roll :2.39 Pitch :0.25 Speed Motor 2 :60 Speed Motor 4 :60

Roll :3.04 Pitch :-0.08 Speed Motor 2 :60 Speed Motor 4 :60

Roll :3.19 Pitch :-0.31 Speed Motor 2 :60 Speed Motor 4 :60

Roll :3.61 Pitch :0.01 Speed Motor 2 :60 Speed Motor 4 :60

after minute

Roll :-1.97 Pitch :-39.30 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.76 Pitch :-41.14 Speed Motor 2 :60 Speed Motor 4 :60

Roll :0.18 Pitch :-40.33 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.65 Pitch :-40.16 Speed Motor 2 :60 Speed Motor 4 :60

Roll :2.78 Pitch :-40.34 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-0.91 Pitch :-39.55 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-1.15 Pitch :-40.28 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-1.29 Pitch :-39.71 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-1.89 Pitch :-41.47 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-2.76 Pitch :-40.03 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.77 Pitch :-41.33 Speed Motor 2 :60 Speed Motor 4 :60

Roll :-0.26 Pitch :-40.90 Speed Motor 2 :60 Speed Motor 4 :60

Roll :1.44 Pitch :-40.30 Speed Motor 2 :60 Speed Motor 4 :60

Are the Roll values reasonable values?
should i make an average of roll values?

Best regards,

The accelerometer must be mounted on an anti-vibration mount, or alternatively the motors, or both...

Soft foam rubber would probably make a big difference.

Most of the motor noise will be higher frequencies than you are interested in, so if the accelerometer section has configurable low-pass filter, try setting that to a lower cut-off frequency.

I mounted the Accelerometer on a styrofoam,but will try soft foam Rubber. What exatly u mean by

MarkT: if the accelerometer section has configurable low-pass filter, try setting that to a lower cut-off frequency.

The mpu6050 has a digital low pass filter for both the gyroscope and accelerometer. Which means that the low pass filter only allows lower frequencies to pass and filters out higher frequencies such that come from your motors. Take a look at the data sheet, search for low pass. http://invensense.com/mems/gyro/documents/RM-MPU-6000A.pdf

huskerwr38: The mpu6050 has a digital low pass filter for both the gyroscope and accelerometer. Which means that the low pass filter only allows lower frequencies to pass and filters out higher frequencies such that come from your motors. Take a look at the data sheet, search for low pass. http://invensense.com/mems/gyro/documents/RM-MPU-6000A.pdf

Thank you, for the reply, i read the section about the digital low pass, it could be very useful, but how can I change bits From Register 26 of Mpu5060? How can i enable it?

OK i searched in the header files for dlpf and i found this: MPU6050.h

uint8_t getDLPFMode(); void setDLPFMode(uint8_t bandwidth);

in the datashet is written:

``````#define MPU6050_DLPF_BW_256         0x00
#define MPU6050_DLPF_BW_188         0x01
#define MPU6050_DLPF_BW_98          0x02
#define MPU6050_DLPF_BW_42          0x03
#define MPU6050_DLPF_BW_20          0x04
#define MPU6050_DLPF_BW_10          0x05
#define MPU6050_DLPF_BW_5           0x06

* DLPF_CFG | Bandwidth | Delay | Bandwidth | Delay | Sample Rate
* ---------+-----------+--------+-----------+--------+-------------
* 0 | 260Hz | 0ms | 256Hz | 0.98ms | 8kHz
* 1 | 184Hz | 2.0ms | 188Hz | 1.9ms | 1kHz
* 2 | 94Hz | 3.0ms | 98Hz | 2.8ms | 1kHz
* 3 | 44Hz | 4.9ms | 42Hz | 4.8ms | 1kHz
* 4 | 21Hz | 8.5ms | 20Hz | 8.3ms | 1kHz
* 5 | 10Hz | 13.8ms | 10Hz | 13.4ms | 1kHz
* 6 | 5Hz | 19.0ms | 5Hz | 18.6ms | 1kHz
* 7 | -- Reserved -- | -- Reserved -- | Reserved
``````

Just to understand 0 means Low pass is off right? So if i do setDLPFmode(0x03) is it filtering?

Waht would happen if i change the Gyro config to + 2000 ° / s?

Setting the register to 0 or 7 the DLPF would be off and your gryo output rate would be at 8kHz. But if you set it to 0x03 then it the DLPF would be filtering and your output rate would be at 1kHz. Setting the gyro config to 2000 degrees/s is the scale of the gyro, which is the maximum angular velocity it can read. So if you have something that will be rotating very fast then you'll want to bump this up to the highest setting, however, the resolution (sensivitivy) won't be as good. But if you have something that doesn't rotate as fast then you'll want to set the scale smaller so you'll have a higher resolution (increased sensitivity). Which is probably what you'll want in this situation.

But I see that in your original post you are concerned with your gyro drifting. You may want to look at using a Kalman filter to use the accelerometer to compensate for the drift. Here is a link for more information: http://forum.arduino.cc/index.php/topic,58048.0.html