Understanding TOF VL53L8CX Sensor on AE3

While running the min/max example for the VL53L8cx sensor I noticed what it was giving me negative/positive ranges for the min value when the camera is in the vertical position

===================
Min depth in mm seen: -450.00
Max depth in mm seen: 3213.00
73.82926

Min depth in mm seen: -440.00
Max depth in mm seen: 4585.00
73.8321

Min depth in mm seen: -430.00
Max depth in mm seen: 3221.00
73.8349

Min depth in mm seen: 244.00
Max depth in mm seen: 4483.00
73.8481

Min depth in mm seen: -426.00
Max depth in mm seen: 3555.00
73.86124

Min depth in mm seen: -444.00
Max depth in mm seen: 4396.00

but when flat on the desktop not seeing the negative min values

====================
Min depth in mm seen: 89.00
Max depth in mm seen: 1877.00
77.49446

Min depth in mm seen: 87.00
Max depth in mm seen: 1872.00
77.49256

Min depth in mm seen: 88.00
Max depth in mm seen: 1875.00
77.4907

Min depth in mm seen: 89.00
Max depth in mm seen: 1857.00
77.4888

and the ranges seem reasonable.

This is the test sketch I am using

import csi
import time
import tof

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.snapshot(time=2000)

clock = time.clock()

tof.init()

while True:
clock.tick()
img = csi0.snapshot()
print(clock.fps())
depth, depth_min, depth_max = tof.read_depth()
print("====================")
print("Min depth in mm seen: %0.2f" % depth_min)
print("Max depth in mm seen: %0.2f" % depth_max)

Second question is how can I get the target status from the sensor. I am not sure its is currently supported in the driver - not really a python programmer so may have missed it when I was poking around in github.

UPDATE: I modified my other sketch that does the visualization:
NEGATIVE NUMBERS with objects

Did a bit more debugging by printing out the depths and adding my own depth_min where it excludes negative numbers

`depth, depth_min, depth_max = tof.read_depth()
print("====================")
print(depth)
valid_depths = [d for d in depth if d >= 0]
print("Min depth in mm seen: %.2f" % depth_min)

if valid_depths:
depth_min = min(valid_depths)
print("Min depth in mm seen: %.2f" % depth_min)
else:
print("No valid depth values found")

print("Max depth in mm seen: %0.2f" % depth_max)`

Output:
====================
[222.0, 201.0, 190.0, 192.0, 196.0, 195.0, 197.0, 204.0, 846.0, 839.0, 236.0, 866.0, 218.0, 557.0, 848.0, 308.0, 878.0, 862.0, 320.0, 328.0, 337.0, 329.0, 327.0, 322.0, 301.0, 294.0, 316.0, 323.0, 335.0, 331.0, 325.0, 322.0, 1728.0, 1707.0, 1756.0, 911.0, 1337.0, 338.0, 329.0, 324.0, 3716.0, 4408.0, 351.0, 4296.0, 363.0, 1237.0, 344.0, 823.0, 285.0, 4435.0, 316.0, 347.0, 327.0, 348.0, 351.0, 335.0, -371.0, -507.0, 4410.0, 308.0, 4080.0, 4024.0, 4016.0, 323.0]
Min depth in mm seen: -507.00
Min depth in mm seen: 190.00
Max depth in mm seen: 4435.00

By excluding the negative gives a descent minimum. My guess is that target status should probably be considered in the driver.

Driver bug, not the sensor. We built the VL53L8CX ULD with target status disabled and copied distance_mm for all 64 zones. The sensor only guarantees distance_mm for zones with target status 5, 6 or 9. Anything else, including “no target”, is leftover data, which is where your negatives come from. On my bench most zones were “no target” and still reported 20 to 1500 mm.

Until the fix is merged (modules/py_tof: Report VL53LX zones without a valid target as NaN. by kwagyeman · Pull Request #3305 · openmv/openmv · GitHub) your d >= 0 filter is the right workaround, though it still passes invalid positive zones.

Thanks @kwagyeman for the response. I have been using the Sparkfun VL53L5CX for a while and have seen the same thing, nd even funnier in about the same cells. Usually the edge cells. But still drives me crazy when I see them

Thanks again.