diff --git a/libraries/AP_Airspeed/AP_Airspeed.cpp b/libraries/AP_Airspeed/AP_Airspeed.cpp index 7ad908378c..340bef649b 100644 --- a/libraries/AP_Airspeed/AP_Airspeed.cpp +++ b/libraries/AP_Airspeed/AP_Airspeed.cpp @@ -755,6 +755,40 @@ bool AP_Airspeed::healthy(uint8_t i) const { return ok; } +// return the current airspeed in m/s +float AP_Airspeed::get_airspeed(uint8_t i) const { + if (!enabled(i)) { + // we can't have negative airspeed so sending an obviously invalid value + return -1.0; + } + return state[i].airspeed; +} + +// return the unfiltered airspeed in m/s +float AP_Airspeed::get_raw_airspeed(uint8_t i) const { + if (!enabled(i)) { + // we can't have negative airspeed so sending an obviously invalid value + return -1.0; + } + return state[i].raw_airspeed; +} + +// return the differential pressure in Pascal for the last airspeed reading +float AP_Airspeed::get_differential_pressure(uint8_t i) const { + if (!enabled(i)) { + return 0.0; + } + return state[i].last_pressure; +} + +// return the current corrected pressure +float AP_Airspeed::get_corrected_pressure(uint8_t i) const { + if (!enabled(i)) { + return 0.0; + } + return state[i].corrected_pressure; +} + #else // build type is not appropriate; provide a dummy implementation: const AP_Param::GroupInfo AP_Airspeed::var_info[] = { AP_GROUPEND }; @@ -764,6 +798,8 @@ void AP_Airspeed::calibrate(bool in_startup) {} bool AP_Airspeed::use(uint8_t i) const { return false; } bool AP_Airspeed::enabled(uint8_t i) const { return false; } bool AP_Airspeed::healthy(uint8_t i) const { return false; } +float AP_Airspeed::get_airspeed(uint8_t i) const { return 0.0; } +float AP_Airspeed::get_differential_pressure(uint8_t i) const { return 0.0; } #if HAL_MSP_AIRSPEED_ENABLED void AP_Airspeed::handle_msp(const MSP::msp_airspeed_data_message_t &pkt) {} diff --git a/libraries/AP_Airspeed/AP_Airspeed.h b/libraries/AP_Airspeed/AP_Airspeed.h index 7e9bd74a95..2d0336be31 100644 --- a/libraries/AP_Airspeed/AP_Airspeed.h +++ b/libraries/AP_Airspeed/AP_Airspeed.h @@ -73,15 +73,11 @@ public: void calibrate(bool in_startup); // return the current airspeed in m/s - float get_airspeed(uint8_t i) const { - return state[i].airspeed; - } + float get_airspeed(uint8_t i) const; float get_airspeed(void) const { return get_airspeed(primary); } // return the unfiltered airspeed in m/s - float get_raw_airspeed(uint8_t i) const { - return state[i].raw_airspeed; - } + float get_raw_airspeed(uint8_t i) const; float get_raw_airspeed(void) const { return get_raw_airspeed(primary); } // return the current airspeed ratio (dimensionless) @@ -114,9 +110,7 @@ public: bool enabled(void) const { return enabled(primary); } // return the differential pressure in Pascal for the last airspeed reading - float get_differential_pressure(uint8_t i) const { - return state[i].last_pressure; - } + float get_differential_pressure(uint8_t i) const; float get_differential_pressure(void) const { return get_differential_pressure(primary); } // update airspeed ratio calibration @@ -173,9 +167,7 @@ public: static AP_Airspeed *get_singleton() { return _singleton; } // return the current corrected pressure, public for AP_Periph - float get_corrected_pressure(uint8_t i) const { - return state[i].corrected_pressure; - } + float get_corrected_pressure(uint8_t i) const; float get_corrected_pressure(void) const { return get_corrected_pressure(primary); }