diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.cpp index 6e7cc156ec..ce7ff42dd6 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.cpp @@ -99,7 +99,7 @@ void AP_RangeFinder_HC_SR04::update(void) const uint32_t now = AP_HAL::millis(); if (value_us == 0) { // no reading; check for timeout: - if (now - last_reading_ms > 1000) { + if (now - state.last_reading_ms > 1000) { // no reading for a second - something is broken state.distance_m = 0.0f; } @@ -125,7 +125,7 @@ void AP_RangeFinder_HC_SR04::update(void) glitch_count = 0; } - last_reading_ms = now; + state.last_reading_ms = now; } // update range_valid state based on distance measured diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.h b/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.h index 0c582e5bfc..c5da562cdc 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.h @@ -34,7 +34,6 @@ private: void check_trigger_pin(); int8_t trigger_pin; - uint32_t last_reading_ms; // system time of last read (used for health reporting) float last_distance_m; // last distance reported (used to prevent glitches in measurement) uint8_t glitch_count; // glitch counter diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_LightWareI2C.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_LightWareI2C.cpp index 5e600ca463..e5d6a94f00 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_LightWareI2C.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_LightWareI2C.cpp @@ -468,6 +468,7 @@ void AP_RangeFinder_LightWareI2C::legacy_timer(void) if (legacy_get_reading(state.distance_m)) { // update range_valid state based on distance measured update_status(); + state.last_reading_ms = AP_HAL::millis(); } else { set_status(RangeFinder::Status::NoData); } @@ -478,6 +479,7 @@ void AP_RangeFinder_LightWareI2C::sf20_timer(void) if (sf20_get_reading(state.distance_m)) { // update range_valid state based on distance measured update_status(); + state.last_reading_ms = AP_HAL::millis(); } else { set_status(RangeFinder::Status::NoData); }