Some improvements
This commit is contained in:
parent
a8cf4068db
commit
83ee05d300
2 changed files with 22 additions and 16 deletions
|
@ -11,6 +11,7 @@ logging.getLogger().setLevel(logging.INFO)
|
|||
sensor = VL53L1XSensor()
|
||||
sensor.open()
|
||||
|
||||
try:
|
||||
while True:
|
||||
sensor.setDirection(Directions.INSIDE)
|
||||
distance_inside = sensor.getDistance()
|
||||
|
@ -24,3 +25,6 @@ while True:
|
|||
|
||||
sleep(DELAY_SECONDS)
|
||||
|
||||
finally:
|
||||
sensor.close()
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class VL53L1XSensor(ToFSensor):
|
|||
def open(self, ranging_mode: int = 2) -> None:
|
||||
self.sensor = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
|
||||
self.sensor.open()
|
||||
self.roi = VL53L1X.VL53L1xUserRoi()
|
||||
|
||||
# Optionally set an explicit timing budget
|
||||
# These values are measurement time in microseconds,
|
||||
|
@ -45,15 +46,16 @@ class VL53L1XSensor(ToFSensor):
|
|||
Directions.OUTSIDE: VL53L1X.VL53L1xUserRoi(6, 15, 9, 12),
|
||||
}
|
||||
|
||||
roi = direction_roi[direction]
|
||||
self.roi = direction_roi[direction]
|
||||
|
||||
self.sensor.stop_ranging()
|
||||
self.sensor.set_user_roi(roi)
|
||||
self.sensor.start_ranging(self.ranging)
|
||||
|
||||
def getDistance(self) -> float:
|
||||
"""Returns new distance in cm."""
|
||||
self.sensor.set_user_roi(self.roi)
|
||||
self.sensor.set_timing(66000, 70)
|
||||
self.sensor.start_ranging(self.ranging)
|
||||
distance = self.sensor.get_distance()
|
||||
self.sensor.stop_ranging()
|
||||
|
||||
return distance / 10
|
||||
|
||||
|
|
Loading…
Reference in a new issue