Subversion Repositories FlightCtrl

Rev

Rev 2069 | Rev 2073 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2069 Rev 2071
Line 120... Line 120...
120
// Value of 2 samples, with range.
120
// Value of 2 samples, with range.
121
uint16_t simpleAirPressure;
121
uint16_t simpleAirPressure;
Line 122... Line 122...
122
 
122
 
123
// Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered.
123
// Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered.
-
 
124
int32_t filteredAirPressure;
-
 
125
 
124
int32_t filteredAirPressure;
126
#define MAX_D_AIRPRESSURE_WINDOW_LENGTH 5
-
 
127
//int32_t lastFilteredAirPressure;
-
 
128
int16_t dAirPressureWindow[MAX_D_AIRPRESSURE_WINDOW_LENGTH];
Line 125... Line 129...
125
int32_t lastFilteredAirPressure;
129
uint8_t dWindowPtr;
126
 
130
 
127
#define MAX_AIRPRESSURE_WINDOW_LENGTH 32
131
#define MAX_AIRPRESSURE_WINDOW_LENGTH 32
128
int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
132
int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
Line 472... Line 476...
472
    if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING) {
476
    if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING) {
Line 473... Line 477...
473
 
477
 
474
      // The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
478
      // The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
Line 475... Line 479...
475
      airPressureSum += simpleAirPressure >> 2;
479
      airPressureSum += simpleAirPressure >> 2;
476
 
-
 
Line 477... Line 480...
477
      lastFilteredAirPressure = filteredAirPressure;
480
 
478
 
481
      uint32_t lastFilteredAirPressure = filteredAirPressure;
479
 
482
 
480
      if (!staticParams.airpressureWindowLength) {
483
      if (!staticParams.airpressureWindowLength) {
481
          filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
484
          filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
482
                          + airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
485
                          + airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
483
      } else {
486
      } else {
484
          // use windowed.
487
          // use windowed.
485
          windowedAirPressure += simpleAirPressure;
488
          windowedAirPressure += simpleAirPressure;
486
          windowedAirPressure -= airPressureWindow[windowPtr];
489
          windowedAirPressure -= airPressureWindow[windowPtr];
487
          airPressureWindow[windowPtr] = simpleAirPressure;
490
          airPressureWindow[windowPtr++] = simpleAirPressure;
Line -... Line 491...
-
 
491
          if (windowPtr == staticParams.airpressureWindowLength) windowPtr = 0;
-
 
492
          filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
-
 
493
      }
488
          windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength;
494
 
489
          filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
495
      dAirPressureWindow[dWindowPtr++] = (int16_t)(filteredAirPressure - lastFilteredAirPressure);
490
      }
496
      if (dWindowPtr == staticParams.dAirpressureWindowLength) dWindowPtr = 0;
491
 
497
 
Line 615... Line 621...
615
int32_t analog_getHeight(void) {
621
int32_t analog_getHeight(void) {
616
  return groundPressure - filteredAirPressure;
622
  return groundPressure - filteredAirPressure;
617
}
623
}
Line 618... Line 624...
618
 
624
 
-
 
625
int16_t analog_getDHeight(void) {
-
 
626
        int16_t result = 0;
-
 
627
        for (int i=0; i<staticParams.dAirpressureWindowLength; i++) {
-
 
628
                result += dAirPressureWindow[i];
-
 
629
        }
619
int16_t analog_getDHeight(void) {
630
 
620
  // dHeight = -dPressure, so here it is the old pressure minus the current, not opposite.
631
  // dHeight = -dPressure, so here it is the old pressure minus the current, not opposite.
621
  return lastFilteredAirPressure - filteredAirPressure;
632
  return result;