Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measurement quality #9

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions adafruit_vl53l4cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@
_VL53L4CD_FIRMWARE_SYSTEM_STATUS = const(0x00E5)
_VL53L4CD_IDENTIFICATION_MODEL_ID = const(0x010F)

_VL53L4CD_RANGE_VALID = const(0x00)
_VL53L4CD_RANGE_WARN_SIGMA_ABOVE_THRESHOLD = const(0x01)
_VL53L4CD_RANGE_WARN_SIGMA_BELOW_THRESHOLD = const(0x02)
_VL53L4CD_RANGE_ERROR_DISTANCE_BELOW_DETECTION_THRESHOLD = const(0x03)
_VL53L4CD_RANGE_ERROR_INVALID_PHASE = const(0x04)
_VL53L4CD_RANGE_ERROR_HW_FAIL = const(0x05)
_VL53L4CD_RANGE_WARN_NO_WRAP_AROUND_CHECK = const(0x06)
_VL53L4CD_RANGE_ERROR_WRAPPED_TARGET_PHASE_MISMATCH = const(0x07)
_VL53L4CD_RANGE_ERROR_PROCESSING_FAIL = const(0x08)
_VL53L4CD_RANGE_ERROR_CROSSTALK_FAIL = const(0x09)
_VL53L4CD_RANGE_ERROR_INTERRUPT = const(0x0A)
_VL53L4CD_RANGE_ERROR_MERGED_TARGET = const(0x0B)
_VL53L4CD_RANGE_ERROR_SIGNAL_TOO_WEAK = const(0x0C)
_VL53L4CD_RANGE_ERROR_OTHER = const(0xFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are _ const(), they will not be available for the user code to use. They are discarded when imported. Could you choose shorter names and declare them globally without the _? Or maybe range_status could be range_valid and just return a boolean? Are you using these error values in your own code?



class VL53L4CD:
"""Driver for the VL53L4CD distance sensor."""
Expand Down Expand Up @@ -199,6 +214,51 @@ def distance(self):
dist = struct.unpack(">H", dist)[0]
return dist / 10

@property
def range_status(self):
"""Measurement validity. If the range status is equal to 0, the distance is valid."""
status_rtn = [
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_HW_FAIL,
_VL53L4CD_RANGE_WARN_SIGMA_BELOW_THRESHOLD,
_VL53L4CD_RANGE_ERROR_INVALID_PHASE,
_VL53L4CD_RANGE_WARN_SIGMA_ABOVE_THRESHOLD,
_VL53L4CD_RANGE_ERROR_WRAPPED_TARGET_PHASE_MISMATCH,
_VL53L4CD_RANGE_ERROR_DISTANCE_BELOW_DETECTION_THRESHOLD,
_VL53L4CD_RANGE_VALID,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_CROSSTALK_FAIL,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_INTERRUPT,
_VL53L4CD_RANGE_WARN_NO_WRAP_AROUND_CHECK,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_OTHER,
_VL53L4CD_RANGE_ERROR_MERGED_TARGET,
_VL53L4CD_RANGE_ERROR_SIGNAL_TOO_WEAK,
]
status = self._read_register(_VL53L4CD_RESULT_RANGE_STATUS, 1)
status = struct.unpack(">B", status)[0]
status = status & 0x1F
if status < 24:
status = status_rtn[status]
else:
status = _VL53L4CD_RANGE_ERROR_OTHER
return status

@property
def sigma(self):
"""Sigma estimator for the noise in the reported target distance in units of centimeters."""
sigma = self._read_register(_VL53L4CD_RESULT_SIGMA, 2)
sigma = struct.unpack(">H", sigma)[0]
return sigma / 40

@property
def timing_budget(self):
"""Ranging duration in milliseconds. Valid range is 10ms to 200ms."""
Expand Down