sparkfun / SparkFun_VL53L1X_Arduino_Library

A library for the laser based VL53L1X Time Of Flight distance sensor capable of detecting a target 4m away!
MIT License
88 stars 50 forks source link

Added One-Shot Ranging trigger #41

Closed josephduchesne closed 2 years ago

josephduchesne commented 3 years ago

I've been exploring sweeping the ROI around to get a "2d" lidar out of each VL53L1x and found that with continuous ranging (StartRanging/StopRanging), the sensor wasn't "taking" the updated ROI consistantly.

I tried waiting for a reading to complete, then stopping the ranging operation in the gap between the timing budget and inter-measurement period, but this was really fragile and would frequently stop working and I'd get results from the wrong SPAD ROI, even though reading the SPAD ROI showed the correct number (which I might put in as another PR with some ROI setting improvements I'm working on).

I think it's just a problem in the internal sensor state machine, where calling stop doesn't take effect immediately, and the ROI settings applied when ranging is active don't work (the datasheet errata talks about how setting ROI when ranging is invalid, but doesn't elaborate).

With this method, I can 100% reliably set the ROI, trigger ranging, then get a single result in a loop, wheras before I had to start, get the results, and stop all spaced out by carefully tuned magic delay numbers.

I tried to match the existing code style in each file, but I'm open to suggestions.

tig commented 3 years ago

I can vouch for this PR.