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

Fix height calculation in setUserRoi(). #13

Closed braincore closed 6 years ago

Grahldg commented 6 years ago

Hi @braincore , thanks for your PR.

The calculation does appear to be correct. The methods are based on those from the ST API, and the lines of code relative to your commit are based on the following from ST:

    user_zone.x_centre = (pRoi->BotRightX + pRoi->TopLeftX  + 1) / 2;
    user_zone.y_centre = (pRoi->TopLeftY  + pRoi->BotRightY + 1) / 2;
    user_zone.width =    (pRoi->BotRightX - pRoi->TopLeftX);
    user_zone.height =   (pRoi->TopLeftY  - pRoi->BotRightY);
    if ((user_zone.width < 3) || (user_zone.height < 3))

Height is calculated as TopLeftY - BotRightY. I found that the way the array is laid out is somewhat counterintuitive. The upper left corner of the array has coordinates (0, 15) and the lower right corner has coordinates (15, 0) and the upper right and lower left corners of your custom array need to be set. For example a possible 4x4 array could have coordinates (7, 11) for the upper left and (11, 7) for the lower right. I found that I had to draw a diagram in order to get my points to work out and to set the custom array successfully. Please let me know if you have any other questions.

braincore commented 6 years ago

Sorry for the confusion! I had altered getUserRoi function in such a way that setUserRoi(getUserRoi()) was not round tripping properly, and wrongly changed setUserRoi rather than undo my getUserRoi changes. I'll abandon this.