Mpu6050 rotation angle

Hi everyone,
I build my student school project in which I need to measure precise pitch angle and rotation angle, Pitch angle is stable with time but rotation angle is not stable and increases with the time . can any one help me to solve this problem?

/* Get tilt angles on X and Y, and rotation angle on Z
 * Angles are given in degrees, displays on SSD1306 OLED
 * 
 * License: MIT
 */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050_light.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);


MPU6050 mpu(Wire);
unsigned long timer = 0;

void setup() {
  Serial.begin(115200);                           // Ensure serial monitor set to this value also    
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))  // Address 0x3C for most of these displays, if doesn't work try 0x3D 
  { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);                                      // Don't proceed, loop forever
  } 
  display.setTextSize(1);             
  display.setTextColor(SSD1306_WHITE);            // Draw white text
  display.clearDisplay();                         
  Wire.begin();
  mpu.begin();
  display.println(F("Calculating gyro offset, do not move MPU6050"));
  display.display();        
  mpu.calcGyroOffsets();                          // This does the calibration
  display.setTextSize(2);          
}

void loop() {
  mpu.update();  
  if((millis()-timer)>10)                         // print data every 10ms
  {                                           
    display.clearDisplay();                       // clear screen
    display.setCursor(0,0);                         
    display.print("P : ");
    display.println(mpu.getAngleX());
    display.print("R : ");
    display.println(mpu.getAngleY());
    display.print("Y : ");
    display.print(mpu.getAngleZ());
    display.display();                            // display data
    timer = millis();  
  }
}

Most likely, the gyro offsets are not correct.

And of course, there is no physical origin reference for the yaw angle (rotation about Z), whereas gravity is the origin reference for the pitch angles.

thank you for reply, can you help me to get the right way to measure the precise Z angle

Please explain what you mean by the "precise Z angle", and what the angle origin reference should be (zero angle).

I mean by" precise angle" a stable reading of angle not change or increasing by-self, the angle origin reference is X axis of mpu sensor to be Zero angle

You must very accurately integrate the rate output over time, with near perfect offset subtraction .

Since the offsets are temperature dependent, you will probably need to measure the effect of temperature on the offset and apply a temperature-dependent correction.

Finally, the sensor noise will add a "random walk" drift.

The MPU-6050 has been obsolete and not manufactured for years, so what you have is some sort of clone or counterfeit. The newer IMU models perform much better, with much lower noise, and will work better for your purpose.

the angle origin reference is X axis of mpu sensor to be Zero angle

That requires a separate calibration step.

many thanks for your reply .
which the newer and much perform better IMU model to get the right angles reading?
Can you help me more to correct my code and write the proper code and do calibration to measure right Z angle.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.