From 19f8462ed3b3ea5600329df1b6e27090c87cb27f Mon Sep 17 00:00:00 2001 From: John Bryan Moore Date: Mon, 23 Jan 2017 00:10:57 -0600 Subject: [PATCH] 1) Add function to VL53L0X.py to show how to call the ST Library directly from Python 2) Update example so time between calls to get_distance is based on device timing --- python/VL53L0X.py | 12 ++++++++++++ python/VL53L0X_example.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/python/VL53L0X.py b/python/VL53L0X.py index 1d3e588..c555a08 100755 --- a/python/VL53L0X.py +++ b/python/VL53L0X.py @@ -90,3 +90,15 @@ def get_distance(self): """Get distance from VL53L0X ToF Sensor""" return tof.getDistance() + # This function included to show how to access the ST library directly + # from python instead of through the simplified interface + def get_timing(self): + Dev = POINTER(c_void_p) + Dev = tof.VL53L0X_get_dev() + budget = c_uint(0) + budget_p = pointer(budget) + Status = tof.VL53L0X_GetMeasurementTimingBudgetMicroSeconds(Dev, budget_p) + if (Status == 0): + return (budget.value + 1000) + else: + return 0 diff --git a/python/VL53L0X_example.py b/python/VL53L0X_example.py index e50abae..54a3794 100755 --- a/python/VL53L0X_example.py +++ b/python/VL53L0X_example.py @@ -31,13 +31,16 @@ tof.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE) -for count in range(1,1001): +timing = tof.get_timing() +print ("Timing %d ms" % (timing/1000)) + +for count in range(1,101): distance = tof.get_distance() if (distance > 0): cumul += distance print ("%d mm, %d cm, %.2f avg, %d diff, %.2f from avg, %d count" % (distance, (distance/10), (float(cumul)/count), (last - distance), (float(cumul)/count)-distance, count)) last = distance - time.sleep(0.10) + time.sleep(timing/1000000.00) tof.stop_ranging()