Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BigBot_v1 PololuDistanceSensorTest Lidar Ares test ... more
VL53L0X.cpp
00001 /** 00002 * @file VL53L0X.cpp 00003 * @author Joel von Rotz (joel.vonrotz@maxonmotor.com) 00004 * @brief 00005 * @version 0.1 00006 * @date 2019-07-30 00007 * 00008 * @copyright Copyright (c) 2019, maxon motor ag - all rights reserved 00009 * 00010 */ 00011 #include "VL53L0X.h " 00012 #include "mbed.h" 00013 00014 #include "vl53l0x_api.h" 00015 #include "vl53l0x_platform.h" 00016 00017 /** 00018 * @brief Construct a new VL53L0X object 00019 * 00020 * The constructor is used to assign the needed values to the VL53L0X-Dev structure. 00021 * 00022 * @param p_i2c_device A pointer to an mbed I2C-object 00023 */ 00024 VL53L0X::VL53L0X(I2C* p_i2c_device) 00025 { 00026 m_vl_dev.i2c_frequency = 400000; 00027 m_vl_dev.i2c_device = p_i2c_device; 00028 m_vl_dev.i2c_address = ADDRESS_DEFAULT; 00029 00030 } 00031 00032 /** 00033 * @brief Set new Device Address 00034 * 00035 * Replaces the current I2C-Address with a new one. Every value can be used. 00036 * Currently there is a small problem on reseting the mbed board: after reset (no power reset) the sensor still 00037 * uses it's new slave address. A power-reset is needed to reset the proximity sensors to their factory settings. 00038 * 00039 * @param address New desired 7-Bit address 00040 * @return true no success 00041 * @return false success 00042 */ 00043 bool VL53L0X::setDeviceAddress(uint8_t address) 00044 { 00045 if(VL53L0X_SetDeviceAddress(&m_vl_dev, address << 1) == 0) 00046 { 00047 m_vl_dev.i2c_address = address; 00048 return 0; 00049 } 00050 return 1; 00051 } 00052 00053 /** 00054 * @brief Initializes the Sensor 00055 * 00056 * After constructing a VL53L0X object, the sensor needs to be initialized by calling this funciton. 00057 * 00058 * @return true never going to happen 00059 * @return false maybe a success 00060 */ 00061 bool VL53L0X::init() 00062 { 00063 VL53L0X_Error Status = VL53L0X_ERROR_NONE; 00064 00065 VL53L0X_GetVersion(&m_vl_version); 00066 00067 if (Status == VL53L0X_ERROR_NONE) 00068 { 00069 Status = VL53L0X_DataInit(&m_vl_dev); // Data initialization 00070 } 00071 if (Status == VL53L0X_ERROR_NONE) 00072 { 00073 Status = VL53L0X_GetDeviceInfo(&m_vl_dev, &m_vl_deviceinfo); 00074 } 00075 return 0; 00076 } 00077 00078 /** 00079 * @brief Set Mode to Continuous 00080 * 00081 * Configures the data acquisition of the sensor to 'continuous' 00082 * 00083 * @return true never going to happen 00084 * @return false maybe a success 00085 */ 00086 bool VL53L0X::setModeContinuous() 00087 { 00088 uint32_t refSpadCount; 00089 uint8_t isApertureSpads; 00090 uint8_t VhvSettings; 00091 uint8_t PhaseCal; 00092 VL53L0X_StaticInit(&m_vl_dev); // Device Initialization 00093 VL53L0X_PerformRefCalibration(&m_vl_dev, &VhvSettings, &PhaseCal); // Device Initialization 00094 VL53L0X_PerformRefSpadManagement(&m_vl_dev, &refSpadCount, &isApertureSpads); // Device Initialization 00095 VL53L0X_SetDeviceMode(&m_vl_dev, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in single ranging mode 00096 00097 return 0; 00098 } 00099 00100 /** 00101 * @brief Starts the Continuous Measurement Session 00102 * 00103 * @return true never going to happen 00104 * @return false maybe a success 00105 */ 00106 bool VL53L0X::startContinuous() 00107 { 00108 VL53L0X_StartMeasurement(&m_vl_dev); 00109 return 0; 00110 } 00111 00112 /** 00113 * @brief Returns measured Range in Millimeters 00114 * 00115 * @return uint16_t distance in [mm] 00116 */ 00117 uint16_t VL53L0X::getRangeMillimeters() 00118 { 00119 VL53L0X_GetRangingMeasurementData(&m_vl_dev, &m_vl_results); 00120 return m_vl_results.RangeMilliMeter; 00121 }
Generated on Wed Jul 13 2022 23:40:16 by
