0
{
  if (myIMU1.dataAvailable() == true)
  {
    float x1 = myIMU1.getGyroX();
    float y1 = myIMU1.getGyroY();
    float z1 = myIMU1.getGyroZ();
    Serial.print(x1, 2);
    Serial.print(F("  "));
    Serial.print(y1, 2);
    Serial.print(F("  "));
    Serial.print(z1, 2);
    Serial.print(F("  "));

    if (myIMU1.dataAvailable()==true)
    {
      q1 = myIMU1.getQuatI();
      q2 = myIMU1.getQuatJ();
      q3 = myIMU1.getQuatK();
      q0 = myIMU1.getQuatReal();
      float quatRadianAccuracy = myIMU1.getQuatRadianAccuracy();
      //toEulerAngle(quatReal,quatI,quatJ,quatK);

      ya= atan2((q1 * q2 + q0 * q3), ((q0 * q0 + q1 * q1) - 0.5f));
      r = -asin(2.0f * (q1 * q3 - q0 * q2));
      p = atan2((q0 * q1 + q2 * q3), ((q0 * q0 + q3 * q3) - 0.5f));
      ya *= 180 / PI;  p *= 180 / PI;  r *= 180 / PI;

      Serial.print(ya, 2);
      Serial.print(F("  "));
      Serial.print(r, 2);
      Serial.print(F("  "));
      Serial.print(p, 2);
      Serial.print(F("  "));
      Serial.println();
    }
  }
  delay(20);
  pitch=r;
   n=sizeof(pitch);
  float myArray[n]={pitch};
  for (i=1;i<n-1;i++)
  {
    if((myArray[i]>myArray[i-1]) && (myArray[i+1]<myArray[i]))
    {
      pitch_dir=1;
    }
    else if((myArray[i]<myArray[i-1]) && (myArray[i+1]>myArray[i]))
    {
      pitch_dir=-1;
    }
    else
    {
      pitch_dir=0;
    }
  }
  Serial.print(pitch_dir);
  delay(20);
    Serial.println();
Serial.println();
3
  • 2
    Sorry for the obvious question but: where is the code that defines array? Your compiler doesn't seem to find it either. – Mat Dec 5 '20 at 8:37
  • 2
    With compiler errors you always need to include the full code, that gave you the error, and the full error message (including the line, where the error happened) as copy&paste text into your question – chrisl Dec 5 '20 at 9:31
  • hey I just edited the code but the maxima or minima is not displaying for the given logic it's just displaying 0; thank you for pointing out the array definition @mat. Also, when I declare 'y1' instead of 'pitch' it tells me ('float y1' redeclared as different kind of symbol) – Vidwath Dec 7 '20 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.