Hi all,

Currently we are trying to make a balancing robot (segway robot) with Mindstorms NXT and the MPU-6050. After quite some effort we managed to connect the MPU-6050 with the NXT, so now we can read the gyro x, y and z axis values properly.

To balance the robot needs both the angle and the angular speed. When we calculate the angular speed,

angularspeed = gyromeasurment - gyroError

the angular speed (when the gyro is stationary) oscillates slightly around 0, so that is good.

And when we calculate the angle with the angular speed (while the sensor is stationary),

Angle = Previous angle + angular speed (* deltaT)

the angle starts at zero and very slowly gets higher or lower, so thats normal too (right?)!

But here is the problem:

When we rotate the sensor randomly (left, right, left) and then try to rotate it back to zero degrees, we notice that the reference point (zero degrees position) has drifted way to the right. The more and faster we move the sensor, the faster the reference point drifts to the right. And when you keep the sensor motionless again , the reference point remains at the same spot (as it should be).

So to us it seems a motion-related drift problem: when you move the sensor, the gyro starts drifting. And not a little, no, when you rotate the sensor left and right for about two seconds, the reference point has rotated left for about 360 degrees (and always to the right!).

Although we are very unexperienced with gyroscopes, we are starting to think the MPU-6050 is faulty. But maybe there is something wrong with the code I wrote, maybe it's something else. We hope this is sufficient information to find the problem.

Thanks in advance

Beuktank

```
...
readResult = I2C_gyrosensor.getData(0x45, readData, len);
if (readResult>=0) {
//measure gyroError
for(int i=1; i<1000; i++){
I2C_gyrosensor.getData(0x45, readData, len);
gyroY = ((readData[0]<<8) | readData[1]);
buffer += gyroY;
}
gyroError = buffer/1000;
while(!Button.ESCAPE.isDown()){
//read ryro
I2C_gyrosensor.getData(0x45, readData, len);
gyroValue = ((readData[0]<<8) | readData[1]);
//calculate angular speed
trueGyro = gyroValue-gyroError;
//calculate angle
angle += trueGyro;
LCD.drawString("Angle = " + angle + " ", 0, 0);
}
}
else {
// display error message...
LCD.drawString("ERROR: " + readResult, 0, 1);
Thread.sleep(2000);
}
```