Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1072

MPU6050 Acts Strange When Roll Limit Is Exceeded

$
0
0

I am working with mpu6050 in my project and my axis limits are -180 degrees to +180 degrees. Only when doing the Roll movement reaches -180 or +180 degrees, (when it is upside down) other values (Yaw and Pitch) change exaggeratedly and reach their approximate maximum values. In the upside down position, all 3 values reach approximately (+ or -) 180 degrees. Can you help me, thanks!
Here is some of my codes about mpu6050:

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps612.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#endif
MPU6050 mpu;
#define OUTPUT_READABLE_YAWPITCHROLL
uint8_t mpuIntStatus, devStatus, fifoBuffer[64], teapotPacket[14] = { '$', 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, '\r', '\n' };
uint16_t packetSize, fifoCount;
bool dmpReady = false;
Quaternion q;                        // [w, x, y, z]         quaternion container
VectorInt16 aa, gy, aaReal, aaWorld;  // [x, y, z]accel sensor measurements   // [x, y, z]  gyro sensor measurements  // [x, y, z] gravity-free accel sensor measurements // [x, y, z] world-frame accel sensor measurements               
VectorFloat gravity;                 // [x, y, z]            gravity vector
float euler[3], ypr[3];              // [psi, theta, phi]    Euler angle container,    // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

void setup() {
  Serial.begin(115200);
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  Wire.begin();
  Wire.setClock(400000);
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
  Fastwire::setup(400, true);
#endif
  mpu.initialize();
  Serial.println(F("Initializing DMP..."));
  devStatus = mpu.dmpInitialize();
  mpu.setXGyroOffset(51);
  mpu.setYGyroOffset(8);
  mpu.setZGyroOffset(21);
  mpu.setXAccelOffset(1150);
  mpu.setYAccelOffset(-50);
  mpu.setZAccelOffset(1060);
  if (devStatus == 0) {
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6);
    Serial.println();
    mpu.PrintActiveOffsets();
    Serial.println(F("Enabling DMP..."));
    mpu.setDMPEnabled(true);
    Serial.println(F(")..."));
    mpuIntStatus = mpu.getIntStatus();
    dmpReady = true;
    packetSize = mpu.dmpGetFIFOPacketSize();
  } else {
    Serial.print(F("DMP Initialization failed (code "));
    Serial.print(devStatus);
    Serial.println(F(")"));
  }
}

void loop() {
  if (!dmpReady) return;
  if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
#ifdef OUTPUT_READABLE_YAWPITCHROLL
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    Serial.print("ypr\t");
    Serial.print(ypr[0] * 180 / M_PI);
    Serial.print("\t");
    Serial.print(ypr[1] * 180 / M_PI);
    Serial.print("\t");
    Serial.print(ypr[2] * 180 / M_PI);
    Serial.println();

#endif
  }
}

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1072

Trending Articles