nomadicseadog / aeroquad

Automatically exported from code.google.com/p/aeroquad
0 stars 0 forks source link

initialization in Altitude.h is buggy #145

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In the initialization part the delays are placed behind the measure calls, but 
they must be before them.

In initialize()
    pressureCount = 0;
    measure();
    delay(5); // delay for temperature
    measure();
    delay(26); // delay for pressure
    measureGround();
    // check if measured ground altitude is valid
    while (abs(getRawData() - getGroundAltitude()) > 10) {
      delay(26);
      measureGround();
    }
should be
    pressureCount = 0;
    delay(5); // delay for temperature
    measure();
    measureGround();
    // check if measured ground altitude is valid
    while (abs(getRawData() - getGroundAltitude()) > 10) {
      measureGround();
    }

    delay(26); // final delay

In measureGround(), which does not belong into the base class other then 
virtual but belongs into the hardware specific class instead, as the base class 
does not know the delays,
  void measureGround(void) {
    // measure initial ground pressure (multiple samples)
    groundAltitude = 0;
    for (int i=0; i < 25; i++) {
      measure();
      delay(26);
      groundAltitude += rawAltitude;
    }
    groundAltitude = groundAltitude / 25.0;
  }
should be
  void measureGround(void) {
    // measure initial ground pressure (multiple samples)
    groundAltitude = 0;
    for (int i=0; i < 25; i++) {
      delay(26);
      measure();
      groundAltitude += rawAltitude;
    }
    groundAltitude = groundAltitude / 25.0;
  }
so this function takes care itself that the delay was done before calling 
measure.
Some constants for the delays were fine, too.

See 
http://aeroquad.com/showthread.php?4376-AeroQuad-Flight-Software-v2-5&p=40876&vi
ewfull=1#post40876 for the post that brought up the bug.

Original issue reported on code.google.com by al...@arcor.de on 6 Dec 2011 at 12:46