Skip to content

Commit 03c380e

Browse files
committed
AP_RangeFinder: ensure that too low and high far states are propagated correctly in DroneCAN
1 parent d6f64da commit 03c380e

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

libraries/AP_RangeFinder/AP_RangeFinder_Backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class AP_RangeFinder_Backend
6666
bool has_data() const;
6767

6868
// returns count of consecutive good readings
69+
// note that this method returning zero does not mean that the device is unhealthy:
6970
uint8_t range_valid_count() const { return state.range_valid_count; }
7071

7172
// return a 3D vector defining the position offset of the sensor

libraries/AP_RangeFinder/AP_RangeFinder_DroneCAN.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,24 @@ void AP_RangeFinder_DroneCAN::update()
8282
{
8383
WITH_SEMAPHORE(_sem);
8484
if ((AP_HAL::millis() - _last_reading_ms) > 500) {
85-
//if data is older than 500ms, report NoData
85+
// if last read was more than 500ms, report NoData
8686
set_status(RangeFinder::Status::NoData);
87-
} else if (_status == RangeFinder::Status::Good && new_data) {
87+
return;
88+
}
89+
90+
if (_status != RangeFinder::Status::Good) {
91+
// handle additional states received by measurement handler
92+
state.last_reading_ms = _last_reading_ms;
93+
set_status(_status);
94+
return;
95+
}
96+
97+
if (_status == RangeFinder::Status::Good && new_data) {
8898
//copy over states
8999
state.distance_m = _distance_m;
90100
state.last_reading_ms = _last_reading_ms;
91101
update_status();
92102
new_data = false;
93-
} else if (_status != RangeFinder::Status::Good) {
94-
//handle additional states received by measurement handler
95-
set_status(_status);
96103
}
97104
}
98105

libraries/AP_RangeFinder/AP_RangeFinder_DroneCAN.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class AP_RangeFinder_DroneCAN : public AP_RangeFinder_Backend {
2828
}
2929
private:
3030
uint8_t _instance;
31+
// _status is the state received from the peripheral - or "NoData" in case of timeout
3132
RangeFinder::Status _status;
3233
float _distance_m;
3334
uint32_t _last_reading_ms;

0 commit comments

Comments
 (0)