1

我们尝试使用手势 LEFT-NORMAL-RIGHT、UP-NORMAL-RIGHT(Arduino+mpu9150)。

我们可以得到这些手势,但并不准确。

它在中间挂起,有时值也不正确。

你能帮我解决这个问题吗?

请检查 ++ 附件的完整代码。

代码:

void guesture() {


  //LEFT & RIGHT
  //Starting Accelerartion condition

  if ( diff_yaw < -250)
  {
    diff_yaw = -(360 + diff_yaw);
  }
  else if (diff_yaw > 250)
  {
    diff_yaw = 360 - diff_yaw;
  }


  if ((aaReal.y < -1500) && (flag1 == false) && (flag2 == false) ) {
    old_time1 = new_time;
    old_yaw = new_yaw;
    flag1 = true;
  } else if ((aaReal.y > 1000) && (flag2 == false) && (flag1 == false)) {
    old_time1 = new_time;
    old_yaw = new_yaw;
    flag2 = true;
  } else if (aaReal.z > 400 && flag11 == false) {
    old_time = new_time;
    flag11 = true;
  } else if (aaReal.z < -400 && flag22 == false) {
    old_time = new_time;
    flag22 = true;
  }

  if ((aaReal.y > 1000) && (flag1 == true)  && (flagZ1 == false)) {
    flagZ1 = true;
  } else if ((aaReal.y < -1500) && (flag2 == true) && (flagZ2 == false)) {
    flagZ2 = true;
  } else if (aaReal.z < -400 && flag11 == true) {
    diff_time = new_time - old_time;
    flag11 = false;
    if (diff_time < 2000 ) {
      flag33 = true;
      old_time = new_time;
    }
  } else if (aaReal.z > 400 && flag22 == true) {
    diff_time = new_time - old_time;
    flag22 = false;
    if (diff_time < 2000 ) {
      flag33 = true;
      old_time = new_time;
    }
  }

  if ((aaReal.y < 1000) && (flagZ1 == true)) {
    flag1 = false;
    flagZ1 = false;
    diff_yaw = new_yaw - old_yaw;
    diff_time = new_time - old_time1;
    if (diff_time < 2000)
    {
      flagN = true;
    }

  } else if ((aaReal.y > -1500) && (flagZ2 == true)) {
    flag2 = false;
    flagZ2 = false;

    diff_yaw = new_yaw - old_yaw;
    diff_time = new_time - old_time1;
    if (diff_time < 2000)
    {
      flagN = true;
    }

  }

  if (flagN == true) {

    if (Iposition == 0 && diff_yaw > 0) {                   //Right
      Iposition = 1;
      flagR = true;
    } else if (Iposition == 0 && (diff_yaw) < 0 ) {         //Left
      Iposition = 2;
      flagL = true;
    } else if (Iposition == 1 && (diff_yaw) < 0 && (diff_yaw) > -25) { //Right-Normal
      Iposition = 0;
      flagNL = true;
    } else if (Iposition == 1 && (diff_yaw) < -25) {       //Right-Left
      Iposition = 2;
      flagL = true;
    } else if (Iposition == 2 && (diff_yaw) > 0 && diff_yaw < 25) { //Left-Normal
      Iposition = 0;
      flagNL = true;
    } else if (Iposition == 2 && diff_yaw > 25) {          //Left-Right
      Iposition = 1;
      flagR = true;
    }
  }
  if (flagN == true  || flag33 == true) {
    if (flagR == true) {
      Serial.println("POSITION : RIGHT");
      flagR = false;
    } else if (flagL == true) {
      Serial.println("POSITION : LEFT");
      flagL = false;
    } else if (flagNL == true) {
      Serial.println("POSITION : NORMAL");
      flagNL = false;
    } else if (Ipos == 0 && pO >= 20 ) {
          Ipos = 1;
          Serial.println("POSITION : UP");
        } else if (Ipos == 0 && pO <= -20 ) {
          Ipos = 2;
          Serial.println("POSITION : DOWN");
        } else if (Ipos == 1 && pO <= 10 && pO >= -10 ) {
          Ipos = 0;
          Serial.println("POSITION : NORMAL");
        }  else if (Ipos == 1 && pO < -5  ) {
          Ipos = 2;
          Serial.println("POSITION : DOWN");
        } else if (Ipos == 2 && pO >= -10 && pO < 0) {
          Ipos = 0;
          Serial.println("POSITION : NORMAL");
        } else if (Ipos == 2 && pO > 0  ) {
          Ipos = 1;
          Serial.println("POSITION : UP");
        }
    flagN = false;
    flag33 = false;
  }


}
4

0 回答 0