Skip to content

Commit ff0acad

Browse files
committed
AP_Proximity: LD06 gets mode filter
1 parent cfdc544 commit ff0acad

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

libraries/AP_Proximity/AP_Proximity_LD06.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void AP_Proximity_LD06::parse_response_data()
170170

171171
// Gets the distance recorded and converts to meters
172172
const float angle_deg = correct_angle_for_orientation(start_angle + angle_step * (i / MEASUREMENT_PAYLOAD_LENGTH));
173-
const float distance_m = UINT16_VALUE(_response[i + 1], _response[i]) * 0.001;
173+
const float distance_m = _dist_filt_mm.apply(UINT16_VALUE(_response[i + 1], _response[i])) * 0.001;
174174
const float confidence = _response[i + 2];
175175

176176
// ignore distance that are out-of-range or have low confidence

libraries/AP_Proximity/AP_Proximity_LD06.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#if AP_PROXIMITY_LD06_ENABLED
3030

3131
#include "AP_Proximity_Backend_Serial.h"
32+
#include <Filter/ModeFilter.h>
3233

3334
#define MESSAGE_LENGTH_LD06 47
3435

@@ -62,6 +63,9 @@ class AP_Proximity_LD06 : public AP_Proximity_Backend_Serial
6263
// Store for error-tracking purposes
6364
uint32_t _last_distance_received_ms;
6465

66+
// distance filter applies to raw measurements
67+
ModeFilterUInt16_Size3 _dist_filt_mm {1};
68+
6569
// face related variables
6670
AP_Proximity_Boundary_3D::Face _last_face;///< last face requested
6771
float _last_angle_deg; ///< yaw angle (in degrees) of _last_distance_m

0 commit comments

Comments
 (0)