2019-07-28 09:08 PM
Hey,
I am using the vl53l1x on a raspberry pi with python (pimoroni library). However, to my knowledge and experience, by default the waiting method for measurement data is BLOCKING. So in Python the get_distance() function takes about as much time as the set timing budget or intermeasurement period, which is simply too time consuming for me.
What would I need to change in the api/core files to realize the non-blocking method or the physical interrupt driven method for the Raspberry Pi described in the docs from ST? I tried to change the "wait_method" in the api (vl53l1_api_core.c) for measurements to NON_BLOCKING and recompiled/reinstalled the module. But in python I still need about the same long duration for finishing the "get_distance()" line (from the Python module), I just want to get the distance measured by the sensor in a given frequency without having to wait for the data in a program blocking way.
Any help would be appreciated
Kind regards,
Malik
EDIT:
So I tried some stuff on my own, which unfortunately failed. Here is what i tried:
In the “vl53l1x_python.c�? file I changed some lines in order to get a non-blocking reading
1.: Introduce new variable/pointer for the GetMeasurementDataReady function
static uint8_t MeasurementDataReady;
static uint8_t *pMeasurementDataReady = &MeasurementDataReady;
2.: change the getDistance() function
int32_t getDistance(VL53L1_Dev_t *dev)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t current_distance = -1;
uint8_t dataready= 0; //new
//Status = VL53L1_WaitMeasurementDataReady(dev); //dont want to wait
Status = VL53L1_GetMeasurementDataReady(dev, pMeasurementDataReady);
dataready = pMeasurementDataReady;//->pready; //is measurement finished //(which parameter is correct here, i dont quite know?)
if (dataready == 1){
Status = VL53L1_GetRangingMeasurementData(dev,
pRangingMeasurementData);
current_distance = pRangingMeasurementData->RangeMilliMeter;
VL53L1_ClearInterruptAndStartMeasurement(dev);
}
return current_distance;
}
So in my theory, this should return -1 for most of the time and the actual distance for when the measurement is done. But this doesn`t work like said before. The “if dataready ==1�? conditition is probably also never met (do I have the wrong pointer?).
I also played with the original form of the function to determine, which function actually consumes the most time. Turns out that for a setting of 33 ms timing budget and 34 ms intermeasurement time the
VL53L1_WaitMeasurementDataReady() takes 4 ms
while the
VL53L1_GetRangingMeasurementData() function takes most of the time (~ 30 ms). This is quite confusing as I didnt see any waiting commands in the api/core files in this function or in functions used by this function.
I hope that this info can help you understand my situation.