Skip to content

Commit

Permalink
AP_Airspeed: inline get_pressure
Browse files Browse the repository at this point in the history
this doesn't gain us anything; it's a private function which is only called in one place and replicates checks that the caller already makes (it devolves into a one-liner, essentially!)

This method is also confusing as it sits next to "get_temperature" in the code, which is actually a match for get_differential_pressure, not get_pressure

... but the chief advantage IMO is not updating the healthy state in this method.
  • Loading branch information
peterbarker committed Feb 24, 2025
1 parent d0824a8 commit 827c8d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
20 changes: 4 additions & 16 deletions libraries/AP_Airspeed/AP_Airspeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,6 @@ void AP_Airspeed::allocate()
}
}

// read the airspeed sensor
float AP_Airspeed::get_pressure(uint8_t i)
{
if (!enabled(i)) {
return 0;
}
float pressure = 0;
if (sensor[i]) {
state[i].healthy = sensor[i]->get_differential_pressure(pressure);
}
return pressure;
}

// get a temperature reading if possible
bool AP_Airspeed::get_temperature(uint8_t i, float &temperature)
{
Expand Down Expand Up @@ -637,13 +624,14 @@ void AP_Airspeed::read(uint8_t i)

#ifndef HAL_BUILD_AP_PERIPH
/*
get the healthy state before we call get_pressure() as
get_pressure() overwrites the healthy state
remember the old healthy state
*/
bool prev_healthy = state[i].healthy;
#endif

float raw_pressure = get_pressure(i);
float raw_pressure = 0;
state[i].healthy = sensor[i]->get_differential_pressure(raw_pressure);

float airspeed_pressure = raw_pressure - get_offset(i);

// remember raw pressure for logging
Expand Down
3 changes: 0 additions & 3 deletions libraries/AP_Airspeed/AP_Airspeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ class AP_Airspeed
uint32_t _log_bit = -1; // stores which bit in LOG_BITMASK is used to indicate we should log airspeed readings

void read(uint8_t i);
// return the differential pressure in Pascal for the last airspeed reading for the requested instance
// returns 0 if the sensor is not enabled
float get_pressure(uint8_t i);

// get the health probability
float get_health_probability(uint8_t i) const {
Expand Down

0 comments on commit 827c8d5

Please sign in to comment.