mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_RangeFinder: signal quality reporting
This commit is contained in:
parent
a7aa74ab20
commit
f6aeb01994
@ -64,6 +64,10 @@ public:
|
||||
// get temperature reading in C. returns true on success and populates temp argument
|
||||
virtual bool get_temp(float &temp) const { return false; }
|
||||
|
||||
// 0 is no return value, 100 is perfect. false means signal
|
||||
// quality is not available
|
||||
virtual bool get_signal_quality_pct(uint8_t &quality_pct) const { return false; }
|
||||
|
||||
protected:
|
||||
|
||||
// update status based on distance measurement
|
||||
|
@ -119,12 +119,14 @@ bool AP_RangeFinder_LightWareSerial::get_reading(float &reading_m)
|
||||
// return average of all valid readings
|
||||
if (valid_count > 0) {
|
||||
reading_m = sum / valid_count;
|
||||
no_signal = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// all readings were invalid so return out-of-range-high value
|
||||
if (invalid_count > 0) {
|
||||
reading_m = MIN(MAX(LIGHTWARE_DIST_MAX_CM, distance_cm_max + LIGHTWARE_OUT_OF_RANGE_ADD_CM), UINT16_MAX) * 0.01f;
|
||||
no_signal = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,11 @@ protected:
|
||||
return MAV_DISTANCE_SENSOR_LASER;
|
||||
}
|
||||
|
||||
bool get_signal_quality_pct(uint8_t &quality_pct) const override {
|
||||
quality_pct = no_signal ? 0 : 100;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// get a reading
|
||||
bool get_reading(float &reading_m) override;
|
||||
@ -35,4 +40,6 @@ private:
|
||||
} protocol_state;
|
||||
uint8_t legacy_valid_count;
|
||||
uint8_t binary_valid_count;
|
||||
|
||||
bool no_signal = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user