Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_RangeFinder: populate last_reading_ms in the backend for some sensors #27620

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
AP_RangeFinder: populate last_reading_ms in the backend for some sensors
  • Loading branch information
rishabsingh3003 committed Jul 23, 2024
commit 28e472f6d2ebf4f127b789aa2ee39505f4799998
4 changes: 2 additions & 2 deletions libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion libraries/AP_RangeFinder/AP_RangeFinder_HC_SR04.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class AP_RangeFinder_HC_SR04 : public AP_RangeFinder_Backend
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

Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_RangeFinder/AP_RangeFinder_LightWareI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading