Browse Source

AP_Airspeed: fix for AnalogIn read_average

master
Pat Hickey 12 years ago committed by Andrew Tridgell
parent
commit
7017a35fc3
  1. 12
      libraries/AP_Airspeed/AP_Airspeed.cpp
  2. 1
      libraries/AP_Airspeed/AP_Airspeed.h

12
libraries/AP_Airspeed/AP_Airspeed.cpp

@ -8,8 +8,7 @@ @@ -8,8 +8,7 @@
* of the License, or (at your option) any later version.
*/
#include <math.h>
#include <AP_Math.h>
#include <AP_Common.h>
#include <AP_HAL.h>
#include <AP_Airspeed.h>
@ -55,10 +54,10 @@ void AP_Airspeed::calibrate() @@ -55,10 +54,10 @@ void AP_Airspeed::calibrate()
if (!_enable) {
return;
}
_source->read();
_source->read_average();
for (c = 0; c < 10; c++) {
hal.scheduler->delay(100);
sum += _source->read();
sum += _source->read_average();
}
_airspeed_raw = sum/c;
_offset.set_and_save(_airspeed_raw);
@ -72,9 +71,8 @@ void AP_Airspeed::read(void) @@ -72,9 +71,8 @@ void AP_Airspeed::read(void)
if (!_enable) {
return;
}
_airspeed_raw = _source->read();
airspeed_pressure = ((_airspeed_raw - _offset) < 0) ?
(_airspeed_raw - _offset) : 0;
_airspeed_raw = _source->read_average();
airspeed_pressure = max(_airspeed_raw - _offset, 0);
_airspeed = 0.7 * _airspeed +
0.3 * sqrt(airspeed_pressure * _ratio);
}

1
libraries/AP_Airspeed/AP_Airspeed.h

@ -21,7 +21,6 @@ public: @@ -21,7 +21,6 @@ public:
// calibrate the airspeed. This must be called on startup if the
// altitude/climb_rate/acceleration interfaces are ever used
// the callback is a delay() like routine
void calibrate();
// return the current airspeed in m/s

Loading…
Cancel
Save