Skip to content

Commit d4f3f86

Browse files
committed
AP_Proximity: LD06 comment and definition improvements
add confidence threshold definition remove unused definitions
1 parent 02528d4 commit d4f3f86

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

libraries/AP_Proximity/AP_Proximity_LD06.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333

3434
// Indices in data array where each value starts being recorded
3535
// See comment below about data payload for more info about formatting
36-
#define START_BEGIN_CHARACTER 0
3736
#define START_DATA_LENGTH 1
38-
#define START_RADAR_SPEED 2
3937
#define START_BEGIN_ANGLE 4
4038
#define START_PAYLOAD 6
4139
#define START_END_ANGLE 42
4240
#define START_CHECK_SUM 46
4341
#define MEASUREMENT_PAYLOAD_LENGTH 3
4442
#define PAYLOAD_COUNT 12
4543

44+
// confidence for each measurement must be this value or higher
45+
#define CONFIDENCE_THRESHOLD 20
46+
4647
/* ------------------------------------------
4748
Data Packet Structure:
4849
Start Character : 1 Byte
@@ -170,24 +171,29 @@ void AP_Proximity_LD06::parse_response_data()
170171
// Gets the distance recorded and converts to meters
171172
const float angle_deg = correct_angle_for_orientation(start_angle + angle_step * (i / MEASUREMENT_PAYLOAD_LENGTH));
172173
const float distance_m = UINT16_VALUE(_response[i + 1], _response[i]) * 0.001;
174+
const float confidence = _response[i + 2];
173175

174-
if (distance_m < distance_min() || distance_m > distance_max() || _response[i + 2] < 20) { // XXX 20 good?
176+
// ignore distance that are out-of-range or have low confidence
177+
if (distance_m < distance_min() || distance_m > distance_max() || confidence < CONFIDENCE_THRESHOLD) {
175178
continue;
176179
}
180+
181+
// ignore distances that are out-of-range (based on user parameters) or within ignore areas
177182
if (ignore_reading(angle_deg, distance_m)) {
178183
continue;
179184
}
180185

181-
uint16_t a2d = (int)(angle_deg / 2.0) * 2;
186+
// use the shortest distance within 2 degree sectors
187+
const uint16_t a2d = (int)(angle_deg / 2.0) * 2;
182188
if (_angle_2deg == a2d) {
183189
if (distance_m < _dist_2deg_m) {
184190
_dist_2deg_m = distance_m;
185191
}
186192
} else {
187-
// New 2deg angle, record the old one
193+
// new 2 degree sector, process the old one
188194

195+
// check if new sector is also a new face
189196
const AP_Proximity_Boundary_3D::Face face = frontend.boundary.get_face((float)_angle_2deg);
190-
191197
if (face != _last_face) {
192198
// distance is for a new face, the previous one can be updated now
193199
if (_last_distance_valid) {
@@ -202,15 +208,17 @@ void AP_Proximity_LD06::parse_response_data()
202208
_last_distance_valid = false;
203209
}
204210

205-
// update shortest distance
211+
// update face's shortest distance
206212
if (!_last_distance_valid || (_dist_2deg_m < _last_distance_m)) {
207213
_last_distance_m = _dist_2deg_m;
208214
_last_distance_valid = true;
209215
_last_angle_deg = (float)_angle_2deg;
210216
}
217+
211218
// update OA database
212219
database_push(_last_angle_deg, _last_distance_m);
213220

221+
// advance to the next 2 degree sector
214222
_angle_2deg = a2d;
215223
_dist_2deg_m = distance_m;
216224
}

libraries/AP_Proximity/AP_Proximity_LD06.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class AP_Proximity_LD06 : public AP_Proximity_Backend_Serial
6868
float _last_distance_m; ///< shortest distance for _last_face
6969
bool _last_distance_valid; ///< true if _last_distance_m is valid
7070

71+
// angle and distance for the latest 2 degree sector
7172
uint16_t _angle_2deg;
7273
float _dist_2deg_m;
7374
};

0 commit comments

Comments
 (0)