![]() |
Laelaps
2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
|
VL6180 Time of Flight Class. More...
#include <laeVL6180.h>
Public Member Functions | |
LaeVL6180Mux (laelaps::LaeI2CMux &mux, int nChan, double fBeamDir, double fDeadzone, const std::string &strNameId="VL6180", const std::string &strDesc="Time-of-Flight range sensor") | |
Intialization constructor. More... | |
LaeVL6180Mux (const LaeVL6180Mux &src) | |
Copy constructor. More... | |
virtual | ~LaeVL6180Mux () |
Destructor. | |
int | initSensor (bool bForce=false) |
Initialize sensor with recommended settings and defaults. More... | |
int | writeDefaults () |
Write defaults to sensor. More... | |
void | readShadowRegs () |
Read shadows register values and update derived data. | |
void | readShadowRegs (byte_t ®RangeOffset, u16_t ®RangeCrossTalk, byte_t ®AlsGain, u16_t ®AlsIntPeriod) |
Read shadows register values, update derived data, and return registers values. More... | |
int | tune (uint_t uRangeOffset, uint_t uRangeCrossTalk, double fAlsGain, uint_t uAlsIntPeriod) |
Tune sensor configuration. More... | |
int | readId (struct VL6180xIdentification &id) |
Read sensor identification. More... | |
double | measureRange (u32_t msecWait=0xffff) |
Measure the sensed target range. More... | |
double | measureAmbientLight (u32_t msecWait=0xffff) |
Measure the sensed ambient light illuminance. More... | |
void | getMeasurements (double &fRange, double &fAmbientLight) |
Get last sensed measurements. More... | |
std::string | getNameId () |
Get sensor assigned name id. More... | |
std::string | getDesc () |
Get sensor short description. More... | |
double | getBeamDir () |
Get sensor direction of the center of emitter IR beam. More... | |
double | getFoV () |
Get sensor field of view. More... | |
void | getMinMax (double &fMin, double &fMax) |
Get sensor's minimum and maximum range. More... | |
std::string | getRadiationType () |
Get radiation type. More... | |
int | calibOffset (int &nOffsetPre, double &fAvgPre, int &nOffsetPost, double &fAvgPost) |
Calibrate part-to-part offset. More... | |
int | calibCrossTalk (int &nCrossTalk) |
Calibrate cross-talk compensation. More... | |
int | readReg8 (u16_t reg, byte_t &val) |
Read an 8-bit value from a register. More... | |
int | readReg16 (u16_t reg, u16_t &val) |
Read a 16-bit value from a register. More... | |
int | writeReg8 (u16_t reg, byte_t val) |
Write an 8-bit value to a register. More... | |
int | writeReg16 (u16_t reg, u16_t val) |
Write a 16-bit value to a register. More... | |
Static Public Member Functions | |
static double | gainEnumToAnalog (vl6180x_als_gain eAlsGain) |
Convert ambient light sensor gain register value enum to analog gain. More... | |
static vl6180x_als_gain | gainAnalogToEnum (double fAlsGain) |
Convert ambient light sensor analog gain to associated register value enum. More... | |
Static Public Attributes | |
static const int | NSenseErrorsThreshold = 10 |
Consecutive sensed error count threshold. More... | |
Protected Member Functions | |
void | lock () |
Lock the share resource. More... | |
void | unlock () |
Unlock the shared resource. More... | |
int | outOfResetInit () |
Initialize sensor out-of-reset. More... | |
u32_t | waitForSensorReady (u16_t regStatus, u32_t msecWait) |
Wait for sensor to be ready. More... | |
u32_t | waitForSensorMeasurement (u32_t msecWait, byte_t bitDone) |
Wait for sensor measurement to complete. More... | |
Protected Attributes | |
laelaps::LaeI2CMux & | m_mux |
I2C multiplexor. | |
int | m_nChan |
multiplexed channel number | |
double | m_fBeamDir |
center of beam direction(radians) | |
double | m_fDeadzone |
sensor deadzone (m) | |
std::string | m_strNameId |
name identifier of sensor | |
std::string | m_strDesc |
short description | |
int | m_nErrorCnt |
consecutive error count | |
bool | m_bBlackListed |
sensor is [not] black listed | |
double | m_fAlsGain |
ambient light sensor analog gain | |
uint_t | m_uAlsIntPeriod |
ALS integration period (msec) | |
byte_t | m_regRangeOffset |
range part-to-part offset register | |
u16_t | m_regRangeCrossTalk |
range cross-talk register | |
byte_t | m_regAlsGain |
ambient light sensor gain register | |
u16_t | m_regAlsIntPeriod |
ALS itegration period register. | |
double | m_fRange |
range (m) | |
double | m_fAmbientLight |
ambient light (lux) | |
pthread_mutex_t | m_mutex |
mutex | |
VL6180 Time of Flight Class.
The interface between the processor and the sensor is through an I2C mulitplexer.
Definition at line 368 of file laeVL6180.h.
sensor::vl6180::LaeVL6180Mux::LaeVL6180Mux | ( | laelaps::LaeI2CMux & | mux, |
int | nChan, | ||
double | fBeamDir, | ||
double | fDeadzone, | ||
const std::string & | strNameId = "VL6180" , |
||
const std::string & | strDesc = "Time-of-Flight range sensor" |
||
) |
Intialization constructor.
mux | I2C multiplexer switch. |
nChan | Mulitplexed channel number. |
fBeamDir | Center of IR beam direction (radians). |
fDeadzone | Sense deadzone range. |
strNameId | Name identifier. |
strDesc | Short description (e.g. location). |
LaeVL6180Mux::LaeVL6180Mux | ( | const LaeVL6180Mux & | src | ) |
Copy constructor.
src | Source object. |
Definition at line 209 of file laeVL6180.cxx.
References m_bBlackListed, m_fAlsGain, m_fAmbientLight, m_fRange, m_mutex, m_nErrorCnt, m_regAlsGain, m_regAlsIntPeriod, m_regRangeCrossTalk, m_regRangeOffset, and m_uAlsIntPeriod.
int LaeVL6180Mux::calibCrossTalk | ( | int & | nCrossTalk | ) |
Calibrate cross-talk compensation.
The offset is stored in register SYSRANGE_CROSSTALK_COMPENSATION_RATE (0x001e).
[out] | nCrossTalk | Cross-talk compensation written to compensation register. |
Definition at line 1037 of file laeVL6180.cxx.
References m_regRangeCrossTalk, measureRange(), readReg8(), VL6180X_RANGE_MAX, and writeReg16().
int LaeVL6180Mux::calibOffset | ( | int & | nOffsetPre, |
double & | fAvgPre, | ||
int & | nOffsetPost, | ||
double & | fAvgPost | ||
) |
Calibrate part-to-part offset.
The offset is stored in register SYSRANGE_PART_TO_PART_RANGE_OFFSET (0x0024).
[out] | nOffsetPre | Current offset register value. |
[out] | fAvgPre | Average measured range on pre-calibrated sensor. |
[out] | nOffsetPost | Post-procedure offset value written to offset register. If equal to nOffsetPre, no calibration was required. |
[out] | fAvgPost | Average measured range after new offset written. |
Definition at line 878 of file laeVL6180.cxx.
References m_regRangeOffset, measureRange(), readReg8(), VL6180X_RANGE_MAX, and writeReg8().
|
static |
Convert ambient light sensor analog gain to associated register value enum.
The mapped enum with the minimum difference between the target analog gain and the actual is chosen.
fAlsGain | Ambient light sensor analog gain. |
Definition at line 1137 of file laeVL6180.cxx.
References AlsGainAnalogTbl, sensor::vl6180::GAIN_1, sensor::vl6180::GAIN_40, and sensor::vl6180::GAIN_NumOf.
Referenced by sensor::vl6180::LaeRangeMuxSubproc::cmdTuneAls(), and tune().
|
static |
Convert ambient light sensor gain register value enum to analog gain.
eAlsGain | Ambient light sensor gain enumeration. |
Definition at line 1125 of file laeVL6180.cxx.
References AlsGainAnalogTbl, sensor::vl6180::GAIN_1, and sensor::vl6180::GAIN_NumOf.
Referenced by sensor::vl6180::LaeRangeMuxSubproc::cmdGetTunes(), sensor::vl6180::LaeVL6180MuxArray::readSensorTunes(), readShadowRegs(), and tune().
|
inline |
Get sensor direction of the center of emitter IR beam.
Definition at line 545 of file laeVL6180.h.
|
inline |
Get sensor short description.
Definition at line 535 of file laeVL6180.h.
|
inline |
Get sensor field of view.
Definition at line 555 of file laeVL6180.h.
References laelaps::degToRad(), and VL6180X_RANGE_FOV.
|
inline |
Get last sensed measurements.
[out] fRange Sensed object range (meters). [out] fAmbienLight Sensed ambient light (lux).
Definition at line 514 of file laeVL6180.h.
|
inline |
Get sensor's minimum and maximum range.
Definition at line 565 of file laeVL6180.h.
References VL6180X_RANGE_MAX, and VL6180X_RANGE_MIN.
|
inline |
Get sensor assigned name id.
Definition at line 525 of file laeVL6180.h.
|
inline |
int LaeVL6180Mux::initSensor | ( | bool | bForce = false | ) |
Initialize sensor with recommended settings and defaults.
bForce | Do [not] force re-initialization. |
Definition at line 232 of file laeVL6180.cxx.
References m_bBlackListed, m_nChan, m_nErrorCnt, m_strNameId, outOfResetInit(), readReg8(), readShadowRegs(), and writeDefaults().
|
inlineprotected |
Lock the share resource.
The lock()/unlock() primitives provide a thread safe mechanism.
Definition at line 718 of file laeVL6180.h.
Referenced by measureAmbientLight(), measureRange(), readId(), and readShadowRegs().
double LaeVL6180Mux::measureAmbientLight | ( | u32_t | msecWait = 0xffff | ) |
Measure the sensed ambient light illuminance.
Single shot mode.
msecWait | Maximum time to wait for the measurement to complete (milliseconds). If the wait time is the special value VL6180X_T_AUTO, then the wait time is auto-calculated base on current sensor configuration. |
Definition at line 696 of file laeVL6180.cxx.
References lock(), m_bBlackListed, m_fAlsGain, m_fAmbientLight, m_nChan, m_nErrorCnt, m_strNameId, m_uAlsIntPeriod, NSenseErrorsThreshold, readReg16(), readReg8(), unlock(), VL6180X_ERR_MEAS, VL6180X_T_AUTO, waitForSensorMeasurement(), waitForSensorReady(), and writeReg8().
double LaeVL6180Mux::measureRange | ( | u32_t | msecWait = 0xffff | ) |
Measure the sensed target range.
Single shot mode.
msecWait | Maximum time to wait for the measurement to complete (milliseconds). If the wait time is the special value VL6180X_T_AUTO, then the wait time is auto-calculated base on current sensor configuration. |
Definition at line 547 of file laeVL6180.cxx.
References lock(), m_bBlackListed, m_fRange, m_nChan, m_nErrorCnt, m_strNameId, NSenseErrorsThreshold, readReg8(), unlock(), VL6180X_ERR_MEAS, VL6180X_RANGE_MAX, VL6180X_RANGE_NO_OBJ, VL6180X_T_AUTO, waitForSensorMeasurement(), waitForSensorReady(), and writeReg8().
Referenced by calibCrossTalk(), and calibOffset().
|
protected |
Initialize sensor out-of-reset.
Definition at line 280 of file laeVL6180.cxx.
References writeReg8().
Referenced by initSensor().
int LaeVL6180Mux::readId | ( | struct VL6180xIdentification & | id | ) |
Read sensor identification.
[out] | id | Identification structure. |
Definition at line 529 of file laeVL6180.cxx.
References lock(), readReg16(), readReg8(), and unlock().
int LaeVL6180Mux::readReg16 | ( | u16_t | reg, |
u16_t & | val | ||
) |
Read a 16-bit value from a register.
reg | 16-bit register address. | |
[out] | val | Read value. |
Definition at line 1193 of file laeVL6180.cxx.
References m_mux, m_nChan, m_strNameId, laelaps::LaeI2CMux::transact(), and VL6180X_ADDR.
Referenced by measureAmbientLight(), readId(), and readShadowRegs().
int LaeVL6180Mux::readReg8 | ( | u16_t | reg, |
byte_t & | val | ||
) |
Read an 8-bit value from a register.
reg | 16-bit register address. | |
[out] | val | Read value. |
Definition at line 1173 of file laeVL6180.cxx.
References m_mux, m_nChan, m_strNameId, laelaps::LaeI2CMux::transact(), and VL6180X_ADDR.
Referenced by calibCrossTalk(), calibOffset(), initSensor(), measureAmbientLight(), measureRange(), readId(), readShadowRegs(), waitForSensorMeasurement(), and waitForSensorReady().
void LaeVL6180Mux::readShadowRegs | ( | byte_t & | regRangeOffset, |
u16_t & | regRangeCrossTalk, | ||
byte_t & | regAlsGain, | ||
u16_t & | regAlsIntPeriod | ||
) |
Read shadows register values, update derived data, and return registers values.
[out] | regRangeOffset | Range part-to-part offset register value |
[out] | regRangeCrossTalk | Range cross-talk register value. |
[out] | regAlsGain | ALS gain register value. |
[out] | regAlsIntPeriod | ALS itegration period register value. |
Definition at line 516 of file laeVL6180.cxx.
References m_regAlsGain, m_regAlsIntPeriod, m_regRangeCrossTalk, m_regRangeOffset, and readShadowRegs().
int LaeVL6180Mux::tune | ( | uint_t | uRangeOffset, |
uint_t | uRangeCrossTalk, | ||
double | fAlsGain, | ||
uint_t | uAlsIntPeriod | ||
) |
Tune sensor configuration.
uRangeOffset | ToF sensor part-to-part offset. If VL6180X_FACTORY_DFT then leave as is. |
uRangeCrossTalk | ToF sensor cross-talk compensation. If VL6180X_FACTORY_DFT then leave as is. |
fAlsGain | Ambient light sensor analog gain. |
uAlsIntPeriod | Ambient light sensor integration period (msec). |
Definition at line 379 of file laeVL6180.cxx.
References laelaps::cap(), gainAnalogToEnum(), gainEnumToAnalog(), m_fAlsGain, m_regAlsGain, m_regAlsIntPeriod, m_regRangeCrossTalk, m_regRangeOffset, m_uAlsIntPeriod, VL6180X_AMBIENT_INT_T_MAX, VL6180X_AMBIENT_INT_T_MIN, VL6180X_FACTORY_DFT, VL6180X_RANGE_OFFSET_MAX, VL6180X_RANGE_OFFSET_MIN, VL6180X_RANGE_XTALK_MAX, VL6180X_RANGE_XTALK_MIN, writeReg16(), and writeReg8().
|
inlineprotected |
Unlock the shared resource.
Definition at line 729 of file laeVL6180.h.
Referenced by measureAmbientLight(), measureRange(), readId(), and readShadowRegs().
|
protected |
Wait for sensor measurement to complete.
msecWait | Maximum time to wait for the measurement to complete (milliseconds). |
bitDone | Bit to check for measurement completion. |
Definition at line 844 of file laeVL6180.cxx.
References readReg8().
Referenced by measureAmbientLight(), and measureRange().
|
protected |
Wait for sensor to be ready.
regStatus | Status register to check. |
msecWait | Maximum time to wait for the measurement to complete (milliseconds). |
Definition at line 816 of file laeVL6180.cxx.
References readReg8().
Referenced by measureAmbientLight(), and measureRange().
int LaeVL6180Mux::writeDefaults | ( | ) |
Write defaults to sensor.
The defaults provide reasonable operation within the Laelaps envirionment.
Definition at line 328 of file laeVL6180.cxx.
References m_regAlsGain, m_regAlsIntPeriod, writeReg16(), and writeReg8().
Referenced by initSensor().
int LaeVL6180Mux::writeReg16 | ( | u16_t | reg, |
u16_t | val | ||
) |
Write a 16-bit value to a register.
reg | 16-bit register address. | |
[in] | val | Write value. |
Definition at line 1243 of file laeVL6180.cxx.
References m_mux, m_nChan, m_strNameId, VL6180X_ADDR, and laelaps::LaeI2CMux::write().
Referenced by calibCrossTalk(), tune(), and writeDefaults().
int LaeVL6180Mux::writeReg8 | ( | u16_t | reg, |
byte_t | val | ||
) |
Write an 8-bit value to a register.
reg | 16-bit register address. | |
[in] | val | Write value. |
Definition at line 1218 of file laeVL6180.cxx.
References m_mux, m_nChan, m_strNameId, VL6180X_ADDR, and laelaps::LaeI2CMux::write().
Referenced by calibOffset(), measureAmbientLight(), measureRange(), outOfResetInit(), tune(), and writeDefaults().
|
static |
Consecutive sensed error count threshold.
The sensor will be black listed if errors exceed this threshold.
Definition at line 376 of file laeVL6180.h.
Referenced by measureAmbientLight(), and measureRange().