AP_RangeFinder: use NaN for invalid rangefinder data

This commit is contained in:
Andrew Tridgell 2023-08-21 10:51:28 +10:00 committed by Peter Barker
parent 1b6c329de5
commit 5f47a94e2b

View File

@ -34,13 +34,13 @@ void AP_RangeFinder_SITL::update(void)
{ {
const float dist = AP::sitl()->get_rangefinder(_instance); const float dist = AP::sitl()->get_rangefinder(_instance);
// negative distance means nothing is connected // nan distance means nothing is connected
if (is_negative(dist)) { if (isnan(dist)) {
state.status = RangeFinder::Status::NoData; state.status = RangeFinder::Status::NoData;
return; return;
} }
state.distance_m = dist; state.distance_m = MAX(0, dist);
state.last_reading_ms = AP_HAL::millis(); state.last_reading_ms = AP_HAL::millis();
// update range_valid state based on distance measured // update range_valid state based on distance measured