MPU-6050 and jrowberg/i2cdevlib Library Problem

Hi All

I am coding a simple robot which turns left and right in response to the angle reading from the MPU-6050.

There is an excellent resource available on GitHub - jrowberg/i2cdevlib: I2C device library collection for AVR/Arduino or other C++-based MCUs, which has been very helpful.

I have managed to get raw values from the MPU-6050 and I have got the angles too, using the example code.

I have modified the example code as follows and this works:

void loop() {
  // if programming failed, don't try to do anything
  if (!dmpReady) return;

  // wait for MPU interrupt or extra packet(s) available
  while (!mpuInterrupt && fifoCount < packetSize) {

    do {
        Serial.print("Current Angle: ");
        Serial.print(ypr[0]);
        Serial.print(" Desired Angle: ");
        Serial.println(desiredAngle);
        spinRight(5);
      }
      else if (ypr[0] > desiredAngle) {
        Serial.print("Current Angle: ");
        Serial.print(ypr[0]);
        Serial.print(" Desired Angle: ");
        Serial.println(desiredAngle);
        spinLeft(5);
      }
  }

However, when I change the code, with the addition of a do…while, then the MPU-6050 gives me a static value that no longer changes.

void loop() {
  // if programming failed, don't try to do anything
  if (!dmpReady) return;

  // wait for MPU interrupt or extra packet(s) available
  while (!mpuInterrupt && fifoCount < packetSize) {

    do {
      if (ypr[0] < desiredAngle) {
        Serial.print("Current Angle: ");
        Serial.print(ypr[0]);
        Serial.print(" Desired Angle: ");
        Serial.println(desiredAngle);
        spinRight(5);
      }
      else if (ypr[0] > desiredAngle) {
        Serial.print("Current Angle: ");
        Serial.print(ypr[0]);
        Serial.print(" Desired Angle: ");
        Serial.println(desiredAngle);
        spinLeft(5);
      }
    } while (ypr[0] != desiredAngle);
  }

Any ideas what I am doing wrong?