Skip to content

Commit d194631

Browse files
committed
AP_RangeFinder: ensure that too low and high far states are propagated correctly in DroneCAN
1 parent 26ac908 commit d194631

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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 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: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,29 @@ 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+
if (_status == RangeFinder::Status::OutOfRangeLow) {
93+
// distance_m starts out as 0 when we are initially on the ground, we want it to return
94+
// to this value upon landing
95+
state.distance_m = 0;
96+
}
97+
state.last_reading_ms = _last_reading_ms;
98+
set_status(_status);
99+
return;
100+
}
101+
102+
if (_status == RangeFinder::Status::Good && new_data) {
88103
//copy over states
89104
state.distance_m = _distance_cm * 0.01f;
90105
state.last_reading_ms = _last_reading_ms;
91106
update_status();
92107
new_data = false;
93-
} else if (_status != RangeFinder::Status::Good) {
94-
//handle additional states received by measurement handler
95-
set_status(_status);
96108
}
97109
}
98110

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
3132
RangeFinder::Status _status;
3233
uint16_t _distance_cm;
3334
uint32_t _last_reading_ms;

0 commit comments

Comments
 (0)