Try to understanding the gyroscope..

Hi guys, I have a hard problem with my gyroscope/accelerometer GY-521 (MPU6050) sensor.

The sensor working good, I tested it and it’s working without problems… BUT…

I notice that the raw gyroscope values are strange… seems that the gyroscope can’t understand correctly the angle inclination of my robot…

when my robot is stopped I change his X and Y rotation angle and I notice that the accelerometer can provide me good values (thx to the minimum 1g of the earth);

these values show a correct angle inclination but you know, if I rotate using more force so my accelerometer give me highest value due to the major acceleration so I need a gyroscope to know the angle rotation of my robot X and Y axys!!! not?

But, as I wrote above, my Gyro giving me strange values… I change the angle of the X and Y axys of my robot and I notice that the gyro values going high when I making this rotation and back to small values when I finish to apply the rotation… like an accelerometer… but without the precision of my accelerometer… indeed after I made this rotation I got values similar to the values I obtained before to start the rotation…

So… exist some way to get some math to find the degrees of my robot X and Y axys?

Here my code:

    #include<Wire.h>
    const int MPU=0x68;  // I2C address of the MPU-6050
    int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
    void setup(){
      Wire.begin();
      Wire.beginTransmission(MPU);
      Wire.write(0x6B);  // PWR_MGMT_1 register
      Wire.write(0);     // set to zero (wakes up the MPU-6050)
      Wire.endTransmission(true);
      Serial.begin(9600);
    }
    void loop()
    {
      Wire.beginTransmission(MPU);
      Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
      AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
      AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
      AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
      Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
      GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
      GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
      GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

      Serial.print("AcX = "); Serial.print(AcX);
      Serial.print(" | AcY = "); Serial.print(AcY);
      Serial.print(" | AcZ = "); Serial.print(AcZ);
      Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
      Serial.print(" | GyX = "); Serial.print(GyX);
      Serial.print(" | GyY = "); Serial.print(GyY);
      Serial.print(" | GyZ = "); Serial.println(GyZ);
      

      delay(333);
    }

I would to tell you that the LED on the sensor is red… in all video I watched I see a green led… :
Please help me!..

You have a rate gyro, which measures the rates at which the sensor is turning, not the orientation angles. You have to integrate the rates to get the angles, but all rate gyros drift, so for accurate results you have to remove the drift first.

This technical paper has a lot of useful information: http://www.thinkmind.org/download.php?articleid=sensordevices_2013_6_40_20221

jremington:
You have a rate gyro, which measures the rates at which the sensor is turning, not the orientation angles. You have to integrate the rates to get the angles, but all rate gyros drift, so for accurate results you have to remove the drift first.

This technical paper has a lot of useful information: http://www.thinkmind.org/download.php?articleid=sensordevices_2013_6_40_20221

ahhh in first THANK YOU for the answer!
Ok, so I have to integrate the rates to get the angles but I need to remove the drift...

Oh my.. I have no idea of what is the "rates" (from your words probably the acceleration of the turn process) and what is the "drift"...
Just a question:
Can I solve this situation using the right code?
In other words, are you sure that I can obtain correct XYZ angle inclination of my robots making the steps you write about?

In other words, are you sure that I can obtain correct XYZ angle inclination of my robots making the steps you write about?

Not with just the gyro. Rate gyros are so noisy that the integration yields nonsense after just a few seconds.

You need external sources of directional information, like the direction of "down" and "north" to correct the gyro and to determine the orientation of the robot.

For some background on the entire process, see these very informative pages: http://www.chrobotics.com/library

jremington:
Not with just the gyro. Rate gyros are so noisy that the integration yields nonsense after just a few seconds.

You need external sources of directional information, like the direction of "down" and "north" to correct the gyro and to determine the orientation of the robot.

For some background on the entire process, see these very informative pages: http://www.chrobotics.com/library

mm wait.. :frowning:

I catch this video from youtube:

or this:

you can notice this guy is using my same sensor and he can obtain the perfect X Y Z angles of the sensor! he can obtain so good these values that he can convert these values into the 3D cube. He rotate the sensor so the 3D cube is rotating!

I need right that!

Not much documentation.

In the first case, much of the code is missing, so one can only guess what was done.

In the second case, the author appears to be using the entire MPU-6050, including the built-in firmware, to get the sensor orientation.

Thank you very much jremington, I damn underestimated this sensor and now I am in a damn dark situation.. :slightly_frowning_face:

The sensor is fine. You just need to do some reading in order to learn how to use it.