Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
sensor::vl6180::LaeVL6180MuxArray Class Reference

VL6180 Time of Flight Array Class. More...

#include <laeVL6180.h>

Inheritance diagram for sensor::vl6180::LaeVL6180MuxArray:
sensor::vl6180::LaeRangeInterface

Public Types

typedef std::vector< sensor::vl6180::LaeVL6180Mux * > VecToFSensors
 time-of-flight sensor vector type
 

Public Member Functions

 LaeVL6180MuxArray (laelaps::LaeI2C &i2cBus)
 Initialization constructor. More...
 
virtual ~LaeVL6180MuxArray ()
 Destructor.
 
virtual int getInterfaceVersion (uint_t &uVerMajor, uint_t &uVerMinor, uint_t &uFwVer)
 Get interface version. More...
 
virtual void clearSensedData ()
 Clear sensed data.
 
virtual int configure (const laelaps::LaeDesc &desc)
 Configure sensor array from product description. More...
 
virtual int configure (const laelaps::LaeTunes &tunes)
 Configure sensor array from tuning parameters. More...
 
virtual int reload (const laelaps::LaeTunes &tunes)
 Reload configuration tuning parameters. More...
 
virtual void exec ()
 Execute task in one cycle to take measurements. More...
 
virtual int getRange (const std::string &strKey, double &fRange)
 Get the shadowed range measurement. More...
 
virtual int getRange (std::vector< std::string > &vecNames, std::vector< double > &vecRanges)
 Get all shadowed sensor range measurements. More...
 
virtual int getAmbientLight (const std::string &strKey, double &fAmbient)
 Get the shadowed ambient light illuminance measurement. More...
 
virtual int getAmbientLight (std::vector< std::string > &vecNames, std::vector< double > &vecAmbient)
 Get all shadowed sensor ambient light illuminance measurements. More...
 
virtual int getSensorProps (const std::string &strKey, std::string &strRadiationType, double &fFoV, double &fBeamDir, double &fMin, double &fMax)
 Get range sensor properties. More...
 
virtual int readSensorIdentity (const std::string &strKey, VL6180xIdentification &ident)
 Read sensor's identification. More...
 
virtual int readSensorTunes (const std::string &strKey, uint_t &uRangeOffset, uint_t &uRangeCrossTalk, double &fAlsGain, uint_t &uAlsIntPeriod)
 Read sensor's current tuning parameters. More...
 
- Public Member Functions inherited from sensor::vl6180::LaeRangeInterface
 LaeRangeInterface (laelaps::LaeI2C &i2cBus)
 Initialization constructor. More...
 
virtual ~LaeRangeInterface ()
 Destructor.
 

Static Public Attributes

static const int AlsFreq = 4
 take an ambient measurement cycle rate
 

Protected Member Functions

int keyIndex (const std::string &strKey)
 

Protected Attributes

laelaps::LaeI2CMux m_mux
 I2C multiplexor.
 
VecToFSensors m_vecToF
 time of flight sensors
 
int m_nAlsIndex
 ambient light sensor index
 
int m_nAlsCounter
 when zero, make measurement
 
- Protected Attributes inherited from sensor::vl6180::LaeRangeInterface
laelaps::LaeI2Cm_i2cBus
 bound I2C bus instance
 

Detailed Description

VL6180 Time of Flight Array Class.

This class holds an set of LaeVL6180 objects to manage a VL6180 sensor array.

Used in 2.0 hardware.

Definition at line 1005 of file laeVL6180.h.

Constructor & Destructor Documentation

LaeVL6180MuxArray::LaeVL6180MuxArray ( laelaps::LaeI2C i2cBus)

Initialization constructor.

Note
The constructor should be kept light weight.
Parameters
i2cbusBound open I2C bus instance.

Definition at line 1274 of file laeVL6180.cxx.

References AlsFreq, m_nAlsCounter, and m_nAlsIndex.

1274  :
1275  LaeRangeInterface(i2cBus), m_mux(i2cBus)
1276 {
1277  m_nAlsIndex = 0;
1279 }
static const int AlsFreq
take an ambient measurement cycle rate
Definition: laeVL6180.h:1008
int m_nAlsCounter
when zero, make measurement
Definition: laeVL6180.h:1184
int m_nAlsIndex
ambient light sensor index
Definition: laeVL6180.h:1183
LaeRangeInterface(laelaps::LaeI2C &i2cBus)
Initialization constructor.
Definition: laeVL6180.h:789
laelaps::LaeI2CMux m_mux
I2C multiplexor.
Definition: laeVL6180.h:1181

Member Function Documentation

int LaeVL6180MuxArray::configure ( const laelaps::LaeDesc desc)
virtual

Configure sensor array from product description.

Parameters
descProduct description.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1311 of file laeVL6180.cxx.

References laelaps::LaeDesc::m_mapDescRangeSensor, m_mux, and m_vecToF.

Referenced by reload().

1312 {
1313  LaeDesc::MapDescRangeSensor::const_iterator iter;
1314  VL6180xIdentification ident;
1315  int rc;
1316 
1317  //
1318  // Time of Flight proximity sensors.
1319  //
1320  for(iter = desc.m_mapDescRangeSensor.begin();
1321  iter != desc.m_mapDescRangeSensor.end();
1322  ++iter)
1323  {
1324  m_vecToF.push_back(new LaeVL6180Mux(m_mux,
1325  iter->second->m_nChan,
1326  iter->second->m_fDir,
1327  iter->second->m_fDeadzone,
1328  iter->first,
1329  iter->second->m_strDesc));
1330  }
1331 
1332  //
1333  // Try to initialize the sensors. But any failures will map only to warnings,
1334  // since we want the robot to still operate.
1335  //
1336  for(size_t i = 0; i < m_vecToF.size(); ++i)
1337  {
1338  if( (rc = m_vecToF[i]->readId(ident)) < 0 )
1339  {
1340  LOGWARN("VL6180 %s sensor: Failed to read identity.",
1341  m_vecToF[i]->getNameId().c_str());
1342  }
1343 
1344  if( (rc = m_vecToF[i]->initSensor(true)) < 0 )
1345  {
1346  LOGWARN("VL6180 %s sensor: Failed to initialize sensor.",
1347  m_vecToF[i]->getNameId().c_str());
1348  }
1349 
1350  if( rc == LAE_OK )
1351  {
1352  LOGDIAG3("VL6180 %s sensor connected:\n"
1353  " Location: %s\n"
1354  " Model: %u v%u.%u\n"
1355  " Module: v%u.%u\n"
1356  " Date: %u %u",
1357  m_vecToF[i]->getNameId().c_str(),
1358  m_vecToF[i]->getDesc().c_str(),
1359  ident.idModel, ident.idModelRevMajor, ident.idModelRevMinor,
1360  ident.idModuleRevMajor, ident.idModuleRevMinor,
1361  ident.idDate, ident.idTime);
1362 
1363  }
1364  }
1365 
1366  return LAE_OK;
1367 }
VL6180 Time of Flight Class.
Definition: laeVL6180.h:368
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
laelaps::LaeI2CMux m_mux
I2C multiplexor.
Definition: laeVL6180.h:1181
MapDescRangeSensor m_mapDescRangeSensor
range sensor descriptions
Definition: laeDesc.h:526
int LaeVL6180MuxArray::configure ( const laelaps::LaeTunes tunes)
virtual

Configure sensor array from tuning parameters.

Parameters
tunesTuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1369 of file laeVL6180.cxx.

References laelaps::LaeTunes::getVL6180Params(), and m_vecToF.

1370 {
1371  string strKey;
1372  int nRangeOffset;
1373  int nRangeCrossTalk;
1374  double fAlsGain;
1375  int nAlsIntPeriod;
1376  int rc;
1377 
1378  for(size_t i = 0; i < m_vecToF.size(); ++i)
1379  {
1380  strKey = m_vecToF[i]->getNameId();
1381 
1382  tunes.getVL6180Params(strKey, nRangeOffset, nRangeCrossTalk,
1383  fAlsGain, nAlsIntPeriod);
1384 
1385  rc = m_vecToF[i]->tune((uint_t)nRangeOffset, (uint_t)nRangeCrossTalk,
1386  fAlsGain, (uint_t)nAlsIntPeriod);
1387 
1388  if( rc == LAE_OK )
1389  {
1390  LOGDIAG3("VL6180 range sensor %s tuned.", strKey.c_str());
1391  }
1392  else
1393  {
1394  LOGERROR("VL6180 range sensor %s: Failed to tune sensor.",
1395  strKey.c_str());
1396  return rc;
1397  }
1398  }
1399 
1400  LOGDIAG2("Tuned VL6180 range sensor group.");
1401 
1402  return LAE_OK;
1403 }
void getVL6180Params(const std::string &strName, int &nTofOffset, int &nTofCrossTalk, double &fAlsGain, int &nAlsIntPeriod) const
Get VL6180 range sensor tune parameters.
Definition: laeTune.cxx:421
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
void LaeVL6180MuxArray::exec ( )
virtual

Execute task in one cycle to take measurements.

Context:
LaeThreadRange thread instance.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1412 of file laeVL6180.cxx.

References AlsFreq, m_nAlsCounter, m_nAlsIndex, and m_vecToF.

1413 {
1414  int nNumSensors;
1415  double fRange;
1416  double fAmbient;
1417 
1418  // no sensors
1419  if( (nNumSensors = (int)m_vecToF.size()) == 0 )
1420  {
1421  return;
1422  }
1423 
1424  // take all range measurements
1425  if( --m_nAlsCounter > 0 )
1426  {
1427  for(int sensorIndex = 0; sensorIndex < nNumSensors; ++sensorIndex)
1428  {
1429  fRange = m_vecToF[sensorIndex]->measureRange(fAmbient);
1430  RtDb.m_range[sensorIndex].m_fRange = fRange;
1431  }
1432  }
1433 
1434  // take single ambient light measurement
1435  else
1436  {
1437  fAmbient = m_vecToF[m_nAlsIndex]->measureAmbientLight();
1438  RtDb.m_range[m_nAlsIndex].m_fAmbientLight = fAmbient;
1439 
1440  m_nAlsIndex = (m_nAlsIndex + 1) % nNumSensors;
1442  }
1443 }
static const int AlsFreq
take an ambient measurement cycle rate
Definition: laeVL6180.h:1008
int m_nAlsCounter
when zero, make measurement
Definition: laeVL6180.h:1184
int m_nAlsIndex
ambient light sensor index
Definition: laeVL6180.h:1183
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::getAmbientLight ( const std::string &  strKey,
double &  fAmbient 
)
virtual

Get the shadowed ambient light illuminance measurement.

The exec() call pulls the measured sensed from the actual sensors.

Parameters
strKeySensor's unique name (key).
[out]fAmbientSensed ambient light (lux).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1482 of file laeVL6180.cxx.

References m_vecToF.

1483 {
1484  double fRange; // not used
1485  int i;
1486 
1487  if( (i = keyIndex(strKey)) >= 0 )
1488  {
1489  m_vecToF[i]->getMeasurements(fRange, fLux);
1490  return LAE_OK;
1491  }
1492  else
1493  {
1494  LOGERROR("VL6180 range sensor %s does not exist.", strKey.c_str());
1495  return -LAE_ECODE_BAD_VAL;
1496  }
1497 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::getAmbientLight ( std::vector< std::string > &  vecNames,
std::vector< double > &  vecAmbient 
)
virtual

Get all shadowed sensor ambient light illuminance measurements.

The exec() call pulls the measured sensed from the actual sensors.

Parameters
strKeySensor's unique name (key).
[out]vecAmbientVector of associated sensor measured ambients (lux).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1499 of file laeVL6180.cxx.

References m_vecToF.

1501 {
1502  double fRange;
1503  double fAmbient;
1504 
1505  vecNames.clear();
1506  vecLux.clear();
1507 
1508  for(size_t i = 0; i < m_vecToF.size(); ++i)
1509  {
1510  m_vecToF[i]->getMeasurements(fRange, fAmbient);
1511 
1512  vecNames.push_back(m_vecToF[i]->getNameId());
1513  vecLux.push_back(fAmbient);
1514  }
1515 
1516  return LAE_OK;
1517 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::getInterfaceVersion ( uint_t &  uVerMajor,
uint_t &  uVerMinor,
uint_t &  uFwVer 
)
virtual

Get interface version.

Parameters
[out]uVerMajorInterface version major number.
[out]uVerMinorInterface version minor number.
[out]uFwVerFirmware version.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1291 of file laeVL6180.cxx.

References laelaps::LAE_OK, LAE_VER_MAJOR, and LAE_VER_MINOR.

1294 {
1295  uVerMajor = LAE_VER_MAJOR(RtDb.m_product.m_uProdHwVer);
1296  uVerMinor = LAE_VER_MINOR(RtDb.m_product.m_uProdHwVer);
1297  uFwVer = 0;
1298 
1299  return laelaps::LAE_OK;
1300 }
#define LAE_VER_MINOR(ver)
Get version minor number from version.
Definition: laelaps.h:177
#define LAE_VER_MAJOR(ver)
Get version major number from version.
Definition: laelaps.h:168
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeVL6180MuxArray::getRange ( const std::string &  strKey,
double &  fRange 
)
virtual

Get the shadowed range measurement.

The exec() call pulls the measured sensed from the actual sensors.

Parameters
strKeySensor's unique name (key).
[out]fRangeSensed object range (meters).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1445 of file laeVL6180.cxx.

References m_vecToF.

1446 {
1447  double fAmbient; // not used
1448  int i;
1449 
1450  if( (i = keyIndex(strKey)) >= 0 )
1451  {
1452  m_vecToF[i]->getMeasurements(fRange, fAmbient);
1453  return LAE_OK;
1454  }
1455  else
1456  {
1457  LOGERROR("VL6180 range sensor %s does not exist.", strKey.c_str());
1458  return -LAE_ECODE_BAD_VAL;
1459  }
1460 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::getRange ( std::vector< std::string > &  vecNames,
std::vector< double > &  vecRanges 
)
virtual

Get all shadowed sensor range measurements.

The exec() call pulls the measured sensed from the actual sensors.

Parameters
[out]vecNamesVector of sensor unique names.
[out]vecRangesVector of associated sensor measured ranges (meters).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1462 of file laeVL6180.cxx.

References m_vecToF.

1464 {
1465  double fRange;
1466  double fAmbient;
1467 
1468  vecNames.clear();
1469  vecRanges.clear();
1470 
1471  for(size_t i = 0; i < m_vecToF.size(); ++i)
1472  {
1473  m_vecToF[i]->getMeasurements(fRange, fAmbient);
1474 
1475  vecNames.push_back(m_vecToF[i]->getNameId());
1476  vecRanges.push_back(fRange);
1477  }
1478 
1479  return LAE_OK;
1480 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::getSensorProps ( const std::string &  strKey,
std::string &  strRadiationType,
double &  fFoV,
double &  fBeamDir,
double &  fMin,
double &  fMax 
)
virtual

Get range sensor properties.

Parameters
strKeySensor's unique name id (key).
[out]strRadiationTypeRadiation type.
[out]fFoVField of View (radians).
[out]fBeamdirCenter of beam direction (radians).
[out]fMinMinimum range (meters).
[out]fMaxMaximum range (meters).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1519 of file laeVL6180.cxx.

References m_vecToF.

1525 {
1526  int i;
1527 
1528  if( (i = keyIndex(strKey)) >= 0 )
1529  {
1530  strRadiationType = m_vecToF[i]->getRadiationType();
1531  fFoV = m_vecToF[i]->getFoV();
1532  fBeamDir = m_vecToF[i]->getBeamDir();
1533  m_vecToF[i]->getMinMax(fMin, fMax);
1534  return LAE_OK;
1535  }
1536  else
1537  {
1538  LOGERROR("VL6180 range sensor %s does not exist.", strKey.c_str());
1539  return -LAE_ECODE_BAD_VAL;
1540  }
1541 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::readSensorIdentity ( const std::string &  strKey,
VL6180xIdentification ident 
)
virtual

Read sensor's identification.

Parameters
strKeySensor's unique name id (key).
[out]identIdentification structure.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1543 of file laeVL6180.cxx.

References m_vecToF.

1545 {
1546  int i;
1547 
1548  if( (i = keyIndex(strKey)) >= 0 )
1549  {
1550  return m_vecToF[i]->readId(ident);
1551  }
1552  else
1553  {
1554  LOGERROR("VL6180 range sensor %s does not exist.", strKey.c_str());
1555  return -LAE_ECODE_BAD_VAL;
1556  }
1557 }
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
int LaeVL6180MuxArray::readSensorTunes ( const std::string &  strKey,
uint_t &  uRangeOffset,
uint_t &  uRangeCrossTalk,
double &  fAlsGain,
uint_t &  uAlsIntPeriod 
)
virtual

Read sensor's current tuning parameters.

Parameters
strKeySensor's unique name id (key).
[out]uRangeOffsetToF sensor part-to-part offset.
[out]uRangeCrossTalkToF sensor cross-talk compensation.
[out]fAlsGainAmbient light sensor analog gain.
[out]uAlsIntPeriodAmbient light sensor integration period (msec).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1559 of file laeVL6180.cxx.

References sensor::vl6180::LaeVL6180Mux::gainEnumToAnalog(), and m_vecToF.

1564 {
1565  byte_t regRangeOffset;
1566  u16_t regRangeCrossTalk;
1567  byte_t regAlsGain;
1568  u16_t regAlsIntPeriod;
1569  int i;
1570 
1571  if( (i = keyIndex(strKey)) >= 0 )
1572  {
1573  m_vecToF[i]->readShadowRegs(regRangeOffset, regRangeCrossTalk,
1574  regAlsGain, regAlsIntPeriod);
1575 
1576  uRangeOffset = (uint_t)regRangeOffset;
1577  uRangeCrossTalk = (uint_t)regRangeCrossTalk;
1578 
1579  fAlsGain = LaeVL6180Mux::gainEnumToAnalog((vl6180x_als_gain)regAlsGain);
1580  uAlsIntPeriod = (uint)regAlsIntPeriod + 1;
1581  return LAE_OK;
1582  }
1583  else
1584  {
1585  LOGERROR("VL6180 range sensor %s does not exist.", strKey.c_str());
1586  return -LAE_ECODE_BAD_VAL;
1587  }
1588 }
vl6180x_als_gain
Ambient Light Sensor gain value enumeration.
Definition: laeVL6180.h:247
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
static double gainEnumToAnalog(vl6180x_als_gain eAlsGain)
Convert ambient light sensor gain register value enum to analog gain.
Definition: laeVL6180.cxx:1125
int LaeVL6180MuxArray::reload ( const laelaps::LaeTunes tunes)
virtual

Reload configuration tuning parameters.

Parameters
tunesTuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from sensor::vl6180::LaeRangeInterface.

Definition at line 1405 of file laeVL6180.cxx.

References configure().

1406 {
1407  LOGDIAG2("Reloading VL6180 range sensor group tuning parameters...");
1408 
1409  return configure(tunes);
1410 }
virtual int configure(const laelaps::LaeDesc &desc)
Configure sensor array from product description.
Definition: laeVL6180.cxx:1311

The documentation for this class was generated from the following files: