File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class AP_RangeFinder_DroneCAN : public AP_RangeFinder_Backend {
2828 }
2929private:
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;
You can’t perform that action at this time.
0 commit comments