33
33
34
34
// Indices in data array where each value starts being recorded
35
35
// See comment below about data payload for more info about formatting
36
- #define START_BEGIN_CHARACTER 0
37
36
#define START_DATA_LENGTH 1
38
- #define START_RADAR_SPEED 2
39
37
#define START_BEGIN_ANGLE 4
40
38
#define START_PAYLOAD 6
41
39
#define START_END_ANGLE 42
42
40
#define START_CHECK_SUM 46
43
41
#define MEASUREMENT_PAYLOAD_LENGTH 3
44
42
#define PAYLOAD_COUNT 12
45
43
44
+ // confidence for each measurement must be this value or higher
45
+ #define CONFIDENCE_THRESHOLD 20
46
+
46
47
/* ------------------------------------------
47
48
Data Packet Structure:
48
49
Start Character : 1 Byte
@@ -170,24 +171,29 @@ void AP_Proximity_LD06::parse_response_data()
170
171
// Gets the distance recorded and converts to meters
171
172
const float angle_deg = correct_angle_for_orientation (start_angle + angle_step * (i / MEASUREMENT_PAYLOAD_LENGTH));
172
173
const float distance_m = UINT16_VALUE (_response[i + 1 ], _response[i]) * 0.001 ;
174
+ const float confidence = _response[i + 2 ];
173
175
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) {
175
178
continue ;
176
179
}
180
+
181
+ // ignore distances that are out-of-range (based on user parameters) or within ignore areas
177
182
if (ignore_reading (angle_deg, distance_m)) {
178
183
continue ;
179
184
}
180
185
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 ;
182
188
if (_angle_2deg == a2d) {
183
189
if (distance_m < _dist_2deg_m) {
184
190
_dist_2deg_m = distance_m;
185
191
}
186
192
} else {
187
- // New 2deg angle, record the old one
193
+ // new 2 degree sector, process the old one
188
194
195
+ // check if new sector is also a new face
189
196
const AP_Proximity_Boundary_3D::Face face = frontend.boundary .get_face ((float )_angle_2deg);
190
-
191
197
if (face != _last_face) {
192
198
// distance is for a new face, the previous one can be updated now
193
199
if (_last_distance_valid) {
@@ -202,15 +208,17 @@ void AP_Proximity_LD06::parse_response_data()
202
208
_last_distance_valid = false ;
203
209
}
204
210
205
- // update shortest distance
211
+ // update face's shortest distance
206
212
if (!_last_distance_valid || (_dist_2deg_m < _last_distance_m)) {
207
213
_last_distance_m = _dist_2deg_m;
208
214
_last_distance_valid = true ;
209
215
_last_angle_deg = (float )_angle_2deg;
210
216
}
217
+
211
218
// update OA database
212
219
database_push (_last_angle_deg, _last_distance_m);
213
220
221
+ // advance to the next 2 degree sector
214
222
_angle_2deg = a2d;
215
223
_dist_2deg_m = distance_m;
216
224
}
0 commit comments