Hi,
I am trying to add the configurable region of interest from the ST API into your library. I’m hoping to use it to narrow the field of vision for a certain project that involves measuring inside a narrow tube. From what I understand this can be programmed to reduce the detection cone to a 15 degree field of vision.
However I think I bit off more than I can chew, I find the ST API really confusing and I need help as to how I can add this in.
This is from the ST API header file:
/** @defgroup VL53L1_ROI_group VL53L1 ROI Functions
* @brief Functions used to select ROIs
* @{
*/
/**
* @brief Set the ROI to be used for ranging
*
* @par Function Description
* The user defined ROI is a rectangle described as per the following system
* from the Top Left corner to the Bottom Right corner.
* <br>Minimal ROI size is 4x4 spads
* @image html roi_coord.png
*
* @param Dev Device Handle
* @param pUserROi Pointer to the Structure definining the ROI
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_SetUserROI(VL53L1_DEV Dev,
VL53L1_UserRoi_t *pUserROi);
/**
* @brief Get the ROI managed by the Device
*
* @par Function Description
* Get the ROI managed by the Device
*
* @param Dev Device Handle
* @param pUserROi Pointer to the Structure definining the ROI
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_GetUserROI(VL53L1_DEV Dev,
VL53L1_UserRoi_t *pUserROi);
/** @} VL53L1_ROI_group */
This is from the ST API cpp file:
/* Group ROI Functions */
VL53L1_Error VL53L1_SetUserROI(VL53L1_DEV Dev,
VL53L1_UserRoi_t *pRoi)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
VL53L1_user_zone_t user_zone;
Status = CheckValidRectRoi(*pRoi);
if (Status != VL53L1_ERROR_NONE)
return VL53L1_ERROR_INVALID_PARAMS;
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))
Status = VL53L1_ERROR_INVALID_PARAMS;
else
Status = VL53L1_set_user_zone(Dev, &user_zone);
LOG_FUNCTION_END(Status);
return Status;
}
VL53L1_Error VL53L1_GetUserROI(VL53L1_DEV Dev,
VL53L1_UserRoi_t *pRoi)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
VL53L1_user_zone_t user_zone;
Status = VL53L1_get_user_zone(Dev, &user_zone);
pRoi->TopLeftX = (2 * user_zone.x_centre - user_zone.width) >> 1;
pRoi->TopLeftY = (2 * user_zone.y_centre + user_zone.height) >> 1;
pRoi->BotRightX = (2 * user_zone.x_centre + user_zone.width) >> 1;
pRoi->BotRightY = (2 * user_zone.y_centre - user_zone.height) >> 1;
LOG_FUNCTION_END(Status);
return Status;
}
/* End Group ROI Functions */
And:
/* Check Rectangle in user's coordinate system:
* 15 TL(x,y) o-----*
* ^ | |
* | *-----o BR(x,y)
* 0------------------------- >15
* check Rectangle definition conforms to the (0,15,15) coordinate system
* with a minimum of 4x4 size
*/
static VL53L1_Error CheckValidRectRoi(VL53L1_UserRoi_t ROI)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
LOG_FUNCTION_START("");
/* Negative check are not necessary because value is unsigned */
if ((ROI.TopLeftX > 15) || (ROI.TopLeftY > 15) ||
(ROI.BotRightX > 15) || (ROI.BotRightY > 15))
Status = VL53L1_ERROR_INVALID_PARAMS;
if ((ROI.TopLeftX > ROI.BotRightX) || (ROI.TopLeftY < ROI.BotRightY))
Status = VL53L1_ERROR_INVALID_PARAMS;
LOG_FUNCTION_END(Status);
return Status;
}
This is the type definition structure for User ROI:
/** @brief Defines User Zone(ROI) parameters
*
*/
typedef struct {
uint8_t TopLeftX; /*!< Top Left x coordinate: 0-15 range */
uint8_t TopLeftY; /*!< Top Left y coordinate: 0-15 range */
uint8_t BotRightX; /*!< Bot Right x coordinate: 0-15 range */
uint8_t BotRightY; /*!< Bot Right y coordinate: 0-15 range */
} VL53L1_UserRoi_t;
/** @brief Defines ROI configuration parameters
*
* Support up a max of 16 zones, Each Zone has the same size
*
*/
This is from the user manual: