Skip to content

Commit

Permalink
Ignore DISTANCE_SENSOR msgs with low signal_quality
Browse files Browse the repository at this point in the history
  • Loading branch information
clydemcqueen committed Jul 18, 2023
1 parent 3f497e9 commit e53f246
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions libraries/AP_RangeFinder/AP_RangeFinder_MAVLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ void AP_RangeFinder_MAVLink::handle_msg(const mavlink_message_t &msg)
mavlink_distance_sensor_t packet;
mavlink_msg_distance_sensor_decode(&msg, &packet);

// only accept distances for the configured orentation
// only accept distances for the configured orientation
if (packet.orientation == orientation()) {
state.last_reading_ms = AP_HAL::millis();
distance_cm = packet.current_distance;
_max_distance_cm = packet.max_distance;
_min_distance_cm = packet.min_distance;
sensor_type = (MAV_DISTANCE_SENSOR)packet.type;
signal_quality = packet.signal_quality;
}
}

Expand Down Expand Up @@ -66,9 +67,9 @@ int16_t AP_RangeFinder_MAVLink::min_distance_cm() const
*/
void AP_RangeFinder_MAVLink::update(void)
{
//Time out on incoming data; if we don't get new
//data in 500ms, dump it
if (AP_HAL::millis() - state.last_reading_ms > AP_RANGEFINDER_MAVLINK_TIMEOUT_MS) {
// time out on incoming data; if we don't get new data in 500ms, dump it
// ignore readings where signal_quality is below cutoff
if (AP_HAL::millis() - state.last_reading_ms > AP_RANGEFINDER_MAVLINK_TIMEOUT_MS || (signal_quality > 0 && signal_quality < 90)) {
set_status(RangeFinder::Status::NoData);
state.distance_m = 0.0f;
} else {
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_RangeFinder/AP_RangeFinder_MAVLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AP_RangeFinder_MAVLink : public AP_RangeFinder_Backend
uint16_t distance_cm;
uint16_t _max_distance_cm;
uint16_t _min_distance_cm;
uint8_t signal_quality;

// start a reading
static bool start_reading(void);
Expand Down

0 comments on commit e53f246

Please sign in to comment.