|
66 | 66 | _VL53L4CD_FIRMWARE_SYSTEM_STATUS = const(0x00E5)
|
67 | 67 | _VL53L4CD_IDENTIFICATION_MODEL_ID = const(0x010F)
|
68 | 68 |
|
| 69 | +RANGE_VALID = const(0x00) |
| 70 | +RANGE_WARN_SIGMA_ABOVE = const(0x01) |
| 71 | +RANGE_WARN_SIGMA_BELOW = const(0x02) |
| 72 | +RANGE_ERROR_DISTANCE_BELOW_DETECTION_THRESHOLD = const(0x03) |
| 73 | +RANGE_ERROR_INVALID_PHASE = const(0x04) |
| 74 | +RANGE_ERROR_HW_FAIL = const(0x05) |
| 75 | +RANGE_WARN_NO_WRAP_AROUND_CHECK = const(0x06) |
| 76 | +RANGE_ERROR_WRAPPED_TARGET_PHASE_MISMATCH = const(0x07) |
| 77 | +RANGE_ERROR_PROCESSING_FAIL = const(0x08) |
| 78 | +RANGE_ERROR_CROSSTALK_FAIL = const(0x09) |
| 79 | +RANGE_ERROR_INTERRUPT = const(0x0A) |
| 80 | +RANGE_ERROR_MERGED_TARGET = const(0x0B) |
| 81 | +RANGE_ERROR_SIGNAL_TOO_WEAK = const(0x0C) |
| 82 | +RANGE_ERROR_OTHER = const(0xFF) |
| 83 | + |
69 | 84 |
|
70 | 85 | class VL53L4CD:
|
71 | 86 | """Driver for the VL53L4CD distance sensor."""
|
@@ -199,6 +214,51 @@ def distance(self):
|
199 | 214 | dist = struct.unpack(">H", dist)[0]
|
200 | 215 | return dist / 10
|
201 | 216 |
|
| 217 | + @property |
| 218 | + def range_status(self): |
| 219 | + """Measurement validity. If the range status is equal to 0, the distance is valid.""" |
| 220 | + status_rtn = [ |
| 221 | + RANGE_ERROR_OTHER, |
| 222 | + RANGE_ERROR_OTHER, |
| 223 | + RANGE_ERROR_OTHER, |
| 224 | + RANGE_ERROR_HW_FAIL, |
| 225 | + RANGE_WARN_SIGMA_BELOW, |
| 226 | + RANGE_ERROR_INVALID_PHASE, |
| 227 | + RANGE_WARN_SIGMA_ABOVE, |
| 228 | + RANGE_ERROR_WRAPPED_TARGET_PHASE_MISMATCH, |
| 229 | + RANGE_ERROR_DISTANCE_BELOW_DETECTION_THRESHOLD, |
| 230 | + RANGE_VALID, |
| 231 | + RANGE_ERROR_OTHER, |
| 232 | + RANGE_ERROR_OTHER, |
| 233 | + RANGE_ERROR_CROSSTALK_FAIL, |
| 234 | + RANGE_ERROR_OTHER, |
| 235 | + RANGE_ERROR_OTHER, |
| 236 | + RANGE_ERROR_OTHER, |
| 237 | + RANGE_ERROR_OTHER, |
| 238 | + RANGE_ERROR_OTHER, |
| 239 | + RANGE_ERROR_INTERRUPT, |
| 240 | + RANGE_WARN_NO_WRAP_AROUND_CHECK, |
| 241 | + RANGE_ERROR_OTHER, |
| 242 | + RANGE_ERROR_OTHER, |
| 243 | + RANGE_ERROR_MERGED_TARGET, |
| 244 | + RANGE_ERROR_SIGNAL_TOO_WEAK, |
| 245 | + ] |
| 246 | + status = self._read_register(_VL53L4CD_RESULT_RANGE_STATUS, 1) |
| 247 | + status = struct.unpack(">B", status)[0] |
| 248 | + status = status & 0x1F |
| 249 | + if status < 24: |
| 250 | + status = status_rtn[status] |
| 251 | + else: |
| 252 | + status = RANGE_ERROR_OTHER |
| 253 | + return status |
| 254 | + |
| 255 | + @property |
| 256 | + def sigma(self): |
| 257 | + """Sigma estimator for the noise in the reported target distance in units of centimeters.""" |
| 258 | + sigma = self._read_register(_VL53L4CD_RESULT_SIGMA, 2) |
| 259 | + sigma = struct.unpack(">H", sigma)[0] |
| 260 | + return sigma / 40 |
| 261 | + |
202 | 262 | @property
|
203 | 263 | def timing_budget(self):
|
204 | 264 | """Ranging duration in milliseconds. Valid range is 10ms to 200ms."""
|
|
0 commit comments