Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeVL6180.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // File: laeVL6180.h
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2016-04-11 13:03:57 -0600 (Mon, 11 Apr 2016) $
10  * $Rev: 4381 $
11  *
12  * \brief Laelaps Time-of-Flight sensors. The ToFs are used as a virtual bumper
13  * for close-in obstacle detection.
14  *
15  * The hardware changed between Laelaps v2.0 and subsequence v2.1+ versions.
16  *
17  * \par Laelaps v2.0
18  * The v2.0 hardware uses an i2c mutliplexer chip to toggle between the
19  * connected sensors. When a sensor was enabled, it is electrically connected
20  * to the odroid's /dev/i2c-3 bus. When disabled, the sensor was electrically
21  * isolated.
22  *
23  * \verbatim
24  * i2c-3 0x70 0x29 0x29 0x29
25  * odroid ------- i2cmux VL6180_0, VL6180_2, ..., VL6180_7
26  * | ^ ^ ^
27  * | i2c-3 | | |
28  * -----------------------------------------
29  * select
30  *
31  * \endverbatim
32  *
33  * \par Laelaps v2.1+
34  * The v2.1+ hardware uses an Arduino compatible sub-processors. The
35  * sub-processor is a slave i2c device to the odroid, and a i2c master to 8
36  * independent soft i2c buses, one per each sensor.
37  *
38  * \verbatim
39  * i2c-3 0x71 soft-i2c-0 0x29
40  * odroid ------- subproc ------------ VL6180_0
41  * |
42  * | soft-i2c-1 0x29
43  * |---------------- VL6180_1
44  * |
45  * ...
46  * |
47  * | soft-i2c-7 0x29
48  * |---------------- VL6180_7
49  *
50  * \endverbatim
51  *
52  * This code is based on the Arduino library freely available from Sparkfun.
53  * See original comment block below.
54  *
55  * \sa https://github.com/sparkfun/ToF_Range_Finder_Sensor-VL6180/tree/master/Libraries/Arduino
56  * \sa https://www.sparkfun.com/products/12785
57  *
58  * \author Robin Knight (robin.knight@roadnarrows.com)
59  *
60  * (C) 2015-2016 RoadNarrows
61  * (http://www.roadNarrows.com)
62  * \n All Rights Reserved
63  */
64 ////////////////////////////////////////////////////////////////////////////////
65 
66 /******************************************************************************
67  * SparkFun_VL6180X.h
68  * Library for VL6180x time of flight range finder.
69  * Casey Kuhns @ SparkFun Electronics
70  * 10/29/2014
71  * https://github.com/sparkfun/SparkFun_ToF_Range_Finder-VL6180_Arduino_Library
72  *
73  * The VL6180x by ST micro is a time of flight range finder that
74  * uses pulsed IR light to determine distances from object at close
75  * range. The average range of a sensor is between 0-200mm
76  *
77  * In this file are the function prototypes in the VL6180x class
78  *
79  * Resources:
80  * This library uses the Arduino Wire.h to complete I2C transactions.
81  *
82  * Development environment specifics:
83  * IDE: Arduino 1.0.5
84  * Hardware Platform: Arduino Pro 3.3V/8MHz
85  * VL6180x Breakout Version: 1.0
86 
87  **Updated for Arduino 1.6.4 5/2015**
88  *
89  * Some settings and initial values come from code written by Kris Winer
90  * VL6180X_t3 Basic Example Code
91  * by: Kris Winer
92  * date: September 1, 2014
93  * license: Beerware - Use this code however you'd like. If you
94  * find it useful you can buy me a beer some time.
95  *
96  * This code is beerware. If you see me (or any other SparkFun employee) at the
97  * local pub, and you've found our code helpful, please buy us a round!
98  *
99  * Distributed as-is; no warranty is given.
100  ******************************************************************************/
101 
102 #ifndef _LAE_VL6180_H
103 #define _LAE_VL6180_H
104 
105 #include <inttypes.h>
106 #include <pthread.h>
107 
108 #include <string>
109 #include <vector>
110 #include <map>
111 
112 #include "rnr/rnrconfig.h"
113 
114 #include "Laelaps/laelaps.h"
115 #include "Laelaps/laeUtils.h"
116 #include "Laelaps/laeDesc.h"
117 #include "Laelaps/laeTune.h"
118 #include "Laelaps/laeI2CMux.h" // v2.0
119 #include "Laelaps/laeToFMux.h" // v2.1+
120 
121 //
122 // Sensor I2C 7-bit address.
123 //
124 #define VL6180X_ADDR 0x29 ///< \h_i2c 7-bit address
125 
126 //
127 // Proximity Sensor Specs
128 //
129 #define VL6180X_IR_LAMBDA 8.5e-07 ///< 850nm wavelength (m)
130 #define VL6180X_RANGE_MIN 0.0 ///< minimum range (m)
131 #define VL6180X_RANGE_MAX 0.2 ///< maximum range (m)
132 #define VL6180X_RANGE_FOV 40.0 ///< field of view (degrees)
133 #define VL6180X_RANGE_NO_OBJ 1000000.0 ///< no object detected
134 
135 // part-to-part offset calibration (2's compliment)
136 #define VL6180X_RANGE_OFFSET_MIN -128 ///< minimum tof offset
137 #define VL6180X_RANGE_OFFSET_MAX 127 ///< maximum tof offset
138 
139 // cross-talk compensation calibration
140 #define VL6180X_RANGE_XTALK_MIN 0 ///< minimum tof cross-talk
141 #define VL6180X_RANGE_XTALK_MAX 0xffff ///< maximum tof cross-talk
142 
143 //
144 // Ambient Light Sensor Specs
145 //
146 #define VL6180X_AMBIENT_RES 0xffff ///< 16-bit ambient light resolution
147 #define VL6180X_AMBIENT_MIN 0.0 ///< minimum ambient light (lux)
148 #define VL6180X_AMBIENT_MAX 1000000.0 ///< maximum ambient light (lux)
149 
150 // analog gain tuning
151 #define VL6180X_AMBIENT_GAIN_MIN 1.0 ///< minimum als analog gain
152 #define VL6180X_AMBIENT_GAIN_MAX 40.0 ///< maximum als analog gain
153 #define VL6180X_AMBIENT_GAIN_MASK 0x07 ///< als analog gain mask
154 
155 // integration period tuning
156 #define VL6180X_AMBIENT_INT_T_MIN 1 ///< minimum als int. period (msec)
157 #define VL6180X_AMBIENT_INT_T_MAX 512 ///< maximum als int. period (msec)
158 #define VL6180X_AMBIENT_INT_T_REC 100 ///< recommended int. period (msec)
159 #define VL6180X_AMBIENT_INT_T_MASK 0x1ff ///< als integration period mask
160 
161 //
162 // Error measurement values.
163 //
164 #define VL6180X_ERR_MEAS -1.0 ///< error meassurement
165 
166 //
167 // Miscellanea
168 //
169 #define VL6180X_T_AUTO 0xffff ///< auto-determine wait time
170 #define VL6180X_FACTORY_DFT -100000 ///< use factory default
171 
172 //
173 // Registers
174 //
175 #define VL6180x_FAILURE_RESET -1
176 
177 #define VL6180X_IDENTIFICATION_MODEL_ID 0x0000
178 #define VL6180X_IDENTIFICATION_MODEL_REV_MAJOR 0x0001
179 #define VL6180X_IDENTIFICATION_MODEL_REV_MINOR 0x0002
180 #define VL6180X_IDENTIFICATION_MODULE_REV_MAJOR 0x0003
181 #define VL6180X_IDENTIFICATION_MODULE_REV_MINOR 0x0004
182 #define VL6180X_IDENTIFICATION_DATE 0x0006 //16bit value
183 #define VL6180X_IDENTIFICATION_TIME 0x0008 //16bit value
184 
185 #define VL6180X_SYSTEM_MODE_GPIO0 0x0010
186 #define VL6180X_SYSTEM_MODE_GPIO1 0x0011
187 #define VL6180X_SYSTEM_HISTORY_CTRL 0x0012
188 #define VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014
189 #define VL6180X_SYSTEM_INTERRUPT_CLEAR 0x0015
190 #define VL6180X_SYSTEM_FRESH_OUT_OF_RESET 0x0016
191 #define VL6180X_SYSTEM_GROUPED_PARAMETER_HOLD 0x0017
192 
193 #define VL6180X_SYSRANGE_START 0x0018
194 #define VL6180X_SYSRANGE_THRESH_HIGH 0x0019
195 #define VL6180X_SYSRANGE_THRESH_LOW 0x001A
196 #define VL6180X_SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B
197 #define VL6180X_SYSRANGE_MAX_CONVERGENCE_TIME 0x001C
198 #define VL6180X_SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E
199 #define VL6180X_SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021
200 #define VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022
201 #define VL6180X_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024
202 #define VL6180X_SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025
203 #define VL6180X_SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026
204 #define VL6180X_SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C
205 #define VL6180X_SYSRANGE_RANGE_CHECK_ENABLES 0x002D
206 #define VL6180X_SYSRANGE_VHV_RECALIBRATE 0x002E
207 #define VL6180X_SYSRANGE_VHV_REPEAT_RATE 0x0031
208 
209 #define VL6180X_SYSALS_START 0x0038
210 #define VL6180X_SYSALS_THRESH_HIGH 0x003A
211 #define VL6180X_SYSALS_THRESH_LOW 0x003C
212 #define VL6180X_SYSALS_INTERMEASUREMENT_PERIOD 0x003E
213 #define VL6180X_SYSALS_ANALOGUE_GAIN 0x003F
214 #define VL6180X_SYSALS_INTEGRATION_PERIOD 0x0040
215 
216 #define VL6180X_RESULT_RANGE_STATUS 0x004D
217 #define VL6180X_RESULT_ALS_STATUS 0x004E
218 #define VL6180X_RESULT_INTERRUPT_STATUS_GPIO 0x004F
219 #define VL6180X_RESULT_ALS_VAL 0x0050
220 #define VL6180X_RESULT_HISTORY_BUFFER 0x0052
221 #define VL6180X_RESULT_RANGE_VAL 0x0062
222 #define VL6180X_RESULT_RANGE_RAW 0x0064
223 #define VL6180X_RESULT_RANGE_RETURN_RATE 0x0066
224 #define VL6180X_RESULT_RANGE_REFERENCE_RATE 0x0068
225 #define VL6180X_RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C
226 #define VL6180X_RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070
227 #define VL6180X_RESULT_RANGE_RETURN_AMB_COUNT 0x0074
228 #define VL6180X_RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078
229 #define VL6180X_RESULT_RANGE_RETURN_CONV_TIME 0x007C
230 #define VL6180X_RESULT_RANGE_REFERENCE_CONV_TIME 0x0080
231 
232 #define VL6180X_READOUT_AVERAGING_SAMPLE_PERIOD 0x010A
233 #define VL6180X_FIRMWARE_BOOTUP 0x0119
234 #define VL6180X_FIRMWARE_RESULT_SCALER 0x0120
235 #define VL6180X_I2C_SLAVE_DEVICE_ADDRESS 0x0212
236 #define VL6180X_INTERLEAVED_MODE_ENABLE 0x02A3
237 
238 namespace sensor
239 {
240  namespace vl6180
241  {
242  /*!
243  * \brief Ambient Light Sensor gain value enumeration.
244  *
245  * From data sheet shows gain values as binary list
246  */
248  {
249  GAIN_20 = 0, ///< actual ALS Gain of 20
250  GAIN_10, ///< actual ALS Gain of 10.32
251  GAIN_5, ///< actual ALS Gain of 5.21
252  GAIN_2_5, ///< actual ALS Gain of 2.60
253  GAIN_1_67, ///< actual ALS Gain of 1.72
254  GAIN_1_25, ///< actual ALS Gain of 1.28
255  GAIN_1 , ///< actual ALS Gain of 1.01
256  GAIN_40, ///< actual ALS Gain of 40
257  GAIN_NumOf ///< number of gain enum values
258  };
259 
261  {
262  uint8_t idModel;
263  uint8_t idModelRevMajor;
264  uint8_t idModelRevMinor;
265  uint8_t idModuleRevMajor;
266  uint8_t idModuleRevMinor;
267  uint16_t idDate;
268  uint16_t idTime;
269  };
270 
271 
272  // -------------------------------------------------------------------------
273  // LaeVL6180SensorInfo Class
274  // -------------------------------------------------------------------------
275 
276  /*!
277  * \brief Container class to hold VL6180 time-of-flight sensor static
278  * information.
279  */
281  {
282  public:
283  int m_nIndex; ///< sensor index
284  int m_nChan; ///< multiplexed channel number
285  double m_fBeamDir; ///< center of beam direction(radians)
286  double m_fDeadzone; ///< sensor deadzone (m)
287  std::string m_strDesc; ///< short description
288 
289  /*!
290  * \brief Default constructor.
291  */
293 
294  /*!
295  * \brief Initialization constructor.
296  *
297  * \param nIndex Sensor index. May be remapped if order of wired sensors
298  * change.
299  * \param nChan Mulitplexed channel number.
300  * \param fBeamDir Center of IR beam direction (radians).
301  * \param fDeadzone Sense deadzone range.
302  * \param strDesc Short description (e.g. location).
303  */
304  LaeVL6180SensorInfo(int nIndex,
305  int nChan,
306  double fBeamDir,
307  double fDeadzone,
308  const std::string &strDesc);
309 
310  /*!
311  * \brief Copy constructor.
312  *
313  * \param src Source object.
314  */
316 
317  /*!
318  * \brief Destructor.
319  */
321 
322  /*!
323  * \brief Assignment operator
324  *
325  * \param rhs Right hand side object.
326  *
327  * \reture *this
328  */
329  LaeVL6180SensorInfo operator=(const LaeVL6180SensorInfo &rhs);
330 
331  /*!
332  * \brief Get sensor properties.
333  *
334  * \param [out] nIndex Sensor index.
335  * \param [out] nChan Mulitplexed channel number.
336  * \param [out] strRadiationType Radiation type.
337  * \param [out] fFoV Field of View (radians).
338  * \param [out] fBeamDir Center of IR beam direction (radians).
339  * \param [out] fDeadzone Sense deadzone range.
340  * \param [out] fMin Minimum range (meters).
341  * \param [out] fMax Maximum range (meters).
342  * \param [out] strDesc Short description (e.g. location).
343  */
344  void getProps(int &nIndex,
345  int &nChan,
346  std::string &strRadiationType,
347  double &fFoV,
348  double &fBeamDir,
349  double &fDeadzone,
350  double &fMin,
351  double &fMax,
352  std::string &strDesc);
353 
354  protected:
355  }; // class LaeVL6180SensorInfo
356 
357 
358  // -------------------------------------------------------------------------
359  // LaeVL6180Mux Class
360  // -------------------------------------------------------------------------
361 
362  /*!
363  * \brief VL6180 Time of Flight Class.
364  *
365  * The interface between the processor and the sensor is through an \h_i2c
366  * mulitplexer.
367  */
369  {
370  public:
371  /*!
372  * \brief Consecutive sensed error count threshold.
373  *
374  * The sensor will be black listed if errors exceed this threshold.
375  */
376  static const int NSenseErrorsThreshold = 10;
377 
378  /*!
379  * \brief Intialization constructor.
380  *
381  * \param mux \h_i2c multiplexer switch.
382  * \param nChan Mulitplexed channel number.
383  * \param fBeamDir Center of IR beam direction (radians).
384  * \param fDeadzone Sense deadzone range.
385  * \param strNameId Name identifier.
386  * \param strDesc Short description (e.g. location).
387  */
389  int nChan,
390  double fBeamDir,
391  double fDeadzone,
392  const std::string &strNameId="VL6180",
393  const std::string &strDesc="Time-of-Flight range sensor");
394 
395  /*!
396  * \brief Copy constructor.
397  *
398  * \param src Source object.
399  */
400  LaeVL6180Mux(const LaeVL6180Mux &src);
401 
402  /*!
403  * \brief Destructor.
404  */
405  virtual ~LaeVL6180Mux();
406 
407  /*!
408  * \brief Initialize sensor with recommended settings and defaults.
409  *
410  * \note Higly recommended to call this method and sensor power-up and
411  * after resets.
412  *
413  * \param bForce Do [not] force re-initialization.
414  *
415  * \copydoc doc_return_std
416  */
417  int initSensor(bool bForce = false);
418 
419  /*!
420  * \brief Write defaults to sensor.
421  *
422  * The defaults provide reasonable operation within the Laelaps
423  * envirionment.
424  *
425  * \copydoc doc_return_std
426  */
427  int writeDefaults();
428 
429  /*!
430  * \brief Read shadows register values and update derived data.
431  */
432  void readShadowRegs();
433 
434  /*!
435  * \brief Read shadows register values, update derived data, and return
436  * registers values.
437  *
438  * \param [out] regRangeOffset Range part-to-part offset register value
439  * \param [out] regRangeCrossTalk Range cross-talk register value.
440  * \param [out] regAlsGain ALS gain register value.
441  * \param [out] regAlsIntPeriod ALS itegration period register value.
442  */
443  void readShadowRegs(byte_t &regRangeOffset,
444  u16_t &regRangeCrossTalk,
445  byte_t &regAlsGain,
446  u16_t &regAlsIntPeriod);
447 
448  /*!
449  * \brief Tune sensor configuration.
450  *
451  * \param uRangeOffset ToF sensor part-to-part offset.
452  * If VL6180X_FACTORY_DFT then leave as is.
453  * \param uRangeCrossTalk ToF sensor cross-talk compensation.
454  * If VL6180X_FACTORY_DFT then leave as is.
455  * \param fAlsGain Ambient light sensor analog gain.
456  * \param uAlsIntPeriod Ambient light sensor integration period (msec).
457  *
458  * \copydoc doc_return_std
459  */
460  int tune(uint_t uRangeOffset, uint_t uRangeCrossTalk,
461  double fAlsGain, uint_t uAlsIntPeriod);
462 
463  /*!
464  * \brief Read sensor identification.
465  *
466  * \param [out] id Identification structure.
467  *
468  * \copydoc doc_return_std
469  */
470  int readId(struct VL6180xIdentification &id);
471 
472  /*!
473  * \brief Measure the sensed target range.
474  *
475  * Single shot mode.
476  *
477  * \param msecWait Maximum time to wait for the measurement to complete
478  * (milliseconds).
479  * If the wait time is the special value VL6180X_T_AUTO,
480  * then the wait time is auto-calculated base on current
481  * sensor configuration.
482  *
483  * \return
484  * On success, the measured object range (meters) is returned.\n
485  * If no object is detected within sensor range,
486  * \ref VL6180X_RANGE_NO_OBJ(1000000.0) is returned.\n
487  * On error, \ref VL6180X_ERR_MEAS(-1.0) is returned.
488  */
489  double measureRange(u32_t msecWait=VL6180X_T_AUTO);
490 
491  /*!
492  * \brief Measure the sensed ambient light illuminance.
493  *
494  * Single shot mode.
495  *
496  * \param msecWait Maximum time to wait for the measurement to complete
497  * (milliseconds).
498  * If the wait time is the special value VL6180X_T_AUTO,
499  * then the wait time is auto-calculated base on current
500  * sensor configuration.
501  *
502  * \return On success, returns measured illuminance (lux).\n
503  * On success, the measured illuminance (lux) is returned.\n
504  * On error, \ref VL6180X_ERR_MEAS(-1.0) is returned.
505  */
506  double measureAmbientLight(u32_t msecWait=VL6180X_T_AUTO);
507 
508  /*!
509  * \brief Get last sensed measurements.
510  *
511  * \parma [out] fRange Sensed object range (meters).
512  * \parma [out] fAmbienLight Sensed ambient light (lux).
513  */
514  void getMeasurements(double &fRange, double &fAmbientLight)
515  {
516  fRange = m_fRange;
517  fAmbientLight = m_fAmbientLight;
518  }
519 
520  /*!
521  * \brief Get sensor assigned name id.
522  *
523  * \return String name.
524  */
525  std::string getNameId()
526  {
527  return m_strNameId;
528  }
529 
530  /*!
531  * \brief Get sensor short description.
532  *
533  * \return String name.
534  */
535  std::string getDesc()
536  {
537  return m_strDesc;
538  }
539 
540  /*!
541  * \brief Get sensor direction of the center of emitter IR beam.
542  *
543  * \return Radians.
544  */
545  double getBeamDir()
546  {
547  return m_fBeamDir;
548  }
549 
550  /*!
551  * \brief Get sensor field of view.
552  *
553  * \return Radians.
554  */
555  double getFoV()
556  {
558  }
559 
560  /*!
561  * \brief Get sensor's minimum and maximum range.
562  *
563  * \return Meters, meters.
564  */
565  void getMinMax(double &fMin, double &fMax)
566  {
567  fMin = VL6180X_RANGE_MIN;
568  fMax = VL6180X_RANGE_MAX;
569  }
570 
571  /*!
572  * \brief Get radiation type.
573  *
574  * \return String.
575  */
576  std::string getRadiationType()
577  {
578  return "infrared";
579  }
580 
581  /*!
582  * \brief Calibrate part-to-part offset.
583  *
584  * The offset is stored in register SYSRANGE_PART_TO_PART_RANGE_OFFSET
585  * (0x0024).
586  *
587  * \sa Section 2.12.3 in datasheet for setup and procedures.
588  *
589  * \param [out] nOffsetPre Current offset register value.
590  * \param [out] fAvgPre Average measured range on pre-calibrated
591  * sensor.
592  * \param [out] nOffsetPost Post-procedure offset value written to
593  * offset register. If equal to nOffsetPre,
594  * no calibration was required.
595  * \param [out] fAvgPost Average measured range after new offset
596  * written.
597  *
598  * \copydoc doc_return_std
599  */
600  int calibOffset(int &nOffsetPre,
601  double &fAvgPre,
602  int &nOffsetPost,
603  double &fAvgPost);
604 
605  /*!
606  * \brief Calibrate cross-talk compensation.
607  *
608  * The offset is stored in register SYSRANGE_CROSSTALK_COMPENSATION_RATE
609  * (0x001e).
610  *
611  * \sa Section 2.12.4 in datasheet for setup and procedures.
612  *
613  * \param [out] nCrossTalk Cross-talk compensation written to
614  * compensation register.
615  *
616  * \copydoc doc_return_std
617  */
618  int calibCrossTalk(int &nCrossTalk);
619 
620  /*!
621  * \brief Read an 8-bit value from a register.
622  *
623  * \param reg 16-bit register address.
624  * \param [out] val Read value.
625  *
626  * \copydoc doc_return_std
627  */
628  int readReg8(u16_t reg, byte_t &val);
629 
630  /*!
631  * \brief Read a 16-bit value from a register.
632  *
633  * \param reg 16-bit register address.
634  * \param [out] val Read value.
635  *
636  * \copydoc doc_return_std
637  */
638  int readReg16(u16_t reg, u16_t &val);
639 
640  /*!
641  * \brief Write an 8-bit value to a register.
642  *
643  * \param reg 16-bit register address.
644  * \param [in] val Write value.
645  *
646  * \copydoc doc_return_std
647  */
648  int writeReg8(u16_t reg, byte_t val);
649 
650  /*!
651  * \brief Write a 16-bit value to a register.
652  *
653  * \param reg 16-bit register address.
654  * \param [in] val Write value.
655  *
656  * \copydoc doc_return_std
657  */
658  int writeReg16(u16_t reg, u16_t val);
659 
660  /*!
661  * \brief Convert ambient light sensor gain register value enum to
662  * analog gain.
663  *
664  * \param eAlsGain Ambient light sensor gain enumeration.
665  *
666  * \return Analog gain.
667  */
668  static double gainEnumToAnalog(vl6180x_als_gain eAlsGain);
669 
670  /*!
671  * \brief Convert ambient light sensor analog gain to associated register
672  * value enum.
673  *
674  * The mapped enum with the minimum difference between the
675  * target analog gain and the actual is chosen.
676  *
677  * \param fAlsGain Ambient light sensor analog gain.
678  *
679  * \return Gain enum.
680  */
681  static vl6180x_als_gain gainAnalogToEnum(double fAlsGain);
682 
683  protected:
684  laelaps::LaeI2CMux &m_mux; ///< \h_i2c multiplexor
685  int m_nChan; ///< multiplexed channel number
686  double m_fBeamDir; ///< center of beam direction(radians)
687  double m_fDeadzone; ///< sensor deadzone (m)
688  std::string m_strNameId; ///< name identifier of sensor
689  std::string m_strDesc; ///< short description
690  int m_nErrorCnt; ///< consecutive error count
691  bool m_bBlackListed; ///< sensor is [not] black listed
692 
693  // tuning and calibration parameters
694  double m_fAlsGain; ///< ambient light sensor analog gain
695  uint_t m_uAlsIntPeriod; ///< ALS integration period (msec)
696 
697  // shadow register values
698  byte_t m_regRangeOffset; ///< range part-to-part offset register
699  u16_t m_regRangeCrossTalk; ///< range cross-talk register
700  byte_t m_regAlsGain; ///< ambient light sensor gain register
701  u16_t m_regAlsIntPeriod; ///< ALS itegration period register
702 
703  // most recent measurements
704  double m_fRange; ///< range (m)
705  double m_fAmbientLight; ///< ambient light (lux)
706 
707  // mutual exclusion
708  pthread_mutex_t m_mutex; ///< mutex
709 
710  /*!
711  * \brief Lock the share resource.
712  *
713  * The lock()/unlock() primitives provide a thread safe mechanism.
714  *
715  * \par Context:
716  * Any.
717  */
718  void lock()
719  {
720  pthread_mutex_lock(&m_mutex);
721  }
722 
723  /*!
724  * \brief Unlock the shared resource.
725  *
726  * \par Context:
727  * Any.
728  */
729  void unlock()
730  {
731  pthread_mutex_unlock(&m_mutex);
732  }
733 
734  /*!
735  * \brief Initialize sensor out-of-reset.
736  *
737  * \note Recommend.
738  *
739  * \copydoc doc_return_std
740  */
741  int outOfResetInit();
742 
743  /*!
744  * \brief Wait for sensor to be ready.
745  *
746  * \param regStatus Status register to check.
747  * \param msecWait Maximum time to wait for the measurement to complete
748  * (milliseconds).
749  *
750  * \return
751  * Returns the number of milliseconds waited. A value \h_gt msecWait
752  * indicates a timeout.
753  */
754  u32_t waitForSensorReady(u16_t regStatus, u32_t msecWait);
755 
756  /*!
757  * \brief Wait for sensor measurement to complete.
758  *
759  * \param msecWait Maximum time to wait for the measurement to complete
760  * (milliseconds).
761  * \param bitDone Bit to check for measurement completion.
762  *
763  * \return
764  * Returns the number of milliseconds waited. A value \h_gt msecWait
765  * indicates a timeout.
766  */
767  u32_t waitForSensorMeasurement(u32_t msecWait, byte_t bitDone);
768 
769  }; // class LaeVL6180Mux
770 
771 
772  // -------------------------------------------------------------------------
773  // LaeRangeInterface Class
774  // -------------------------------------------------------------------------
775 
776  /*!
777  * \brief Range sensors interface base class.
778  */
780  {
781  public:
782  /*!
783  * \brief Initialization constructor.
784  *
785  * \note The constructor should be kept light weight.
786  *
787  * \param i2cbus Bound open \h_i2c bus instance.
788  */
789  LaeRangeInterface(laelaps::LaeI2C &i2cBus) : m_i2cBus(i2cBus)
790  {
791  }
792 
793  /*!
794  * \brief Destructor.
795  */
797  {
798  }
799 
800  /*!
801  * \brief Get interface version.
802  *
803  * \param [out] uVerMajor Interface version major number.
804  * \param [out] uVerMinor Interface version minor number.
805  * \param [out] uFwVer Firmware version.
806  *
807  * \copydoc doc_return_std
808  */
809  virtual int getInterfaceVersion(uint_t &uVerMajor,
810  uint_t &uVerMinor,
811  uint_t &uFwVer)
812  {
813  uVerMajor = 0;
814  uVerMinor = 0;
815  uFwVer = 0;
816 
818  }
819 
820  /*!
821  * \brief Clear sensed data.
822  */
823  virtual void clearSensedData()
824  {
825  }
826 
827  /*!
828  * \brief Configure sensor array from product description.
829  *
830  * \param desc Product description.
831  *
832  * \copydoc doc_return_std
833  */
834  virtual int configure(const laelaps::LaeDesc &desc)
835  {
837  }
838 
839  /*!
840  * \brief Configure sensor array from tuning parameters.
841  *
842  * \param tunes Tuning parameters.
843  *
844  * \copydoc doc_return_std
845  */
846  virtual int configure(const laelaps::LaeTunes &tunes)
847  {
849  }
850 
851  /*!
852  * \brief Reload configuration tuning parameters.
853  *
854  * \param tunes Tuning parameters.
855  *
856  * \copydoc doc_return_std
857  */
858  virtual int reload(const laelaps::LaeTunes &tunes)
859  {
861  }
862 
863  /*!
864  * \brief Execute task in one cycle to take measurements.
865  *
866  * \par Context:
867  * LaeThreadRange thread instance.
868  */
869  virtual void exec()
870  {
871  }
872 
873  /*!
874  * \brief Get a range measurement.
875  *
876  * \param strKey Sensor's unique name (key).
877  * \param [out] fRange Sensed object range (meters).
878  *
879  * \copydoc doc_return_std
880  */
881  virtual int getRange(const std::string &strKey, double &fRange)
882  {
884  }
885 
886  /*!
887  * \brief Get all sensor range measurements.
888  *
889  * \param [out] vecNames Vector of sensor unique names.
890  * \param [out] vecRanges Vector of associated sensor measured ranges
891  * (meters).
892  *
893  * \copydoc doc_return_std
894  */
895  virtual int getRange(std::vector<std::string> &vecNames,
896  std::vector<double> &vecRanges)
897  {
899  }
900 
901  /*!
902  * \brief Get an ambient light illuminance measurement.
903  *
904  * \param strKey Sensor's unique name (key).
905  * \param [out] fAmbient Sensed ambient light (lux).
906  *
907  * \copydoc doc_return_std
908  */
909  virtual int getAmbientLight(const std::string &strKey,
910  double &fAmbient)
911  {
913  }
914 
915  /*!
916  * \brief Get all sensor ambient light illuminance measurements.
917  *
918  * \param strKey Sensor's unique name (key).
919  * \param [out] vecAmbient Vector of associated sensor measured ambients
920  * (lux).
921  *
922  * \copydoc doc_return_std
923  */
924  virtual int getAmbientLight(std::vector<std::string> &vecNames,
925  std::vector<double> &vecAmbient)
926  {
928  }
929 
930  /*!
931  * \brief Get range sensor properties.
932  *
933  * \param strKey Sensor's unique name id (key).
934  * \param [out] strRadiationType Radiation type.
935  * \param [out] fFoV Field of View (radians).
936  * \param [out] fBeamdir Center of beam direction (radians).
937  * \param [out] fMin Minimum range (meters).
938  * \param [out] fMax Maximum range (meters).
939  *
940  * \copydoc doc_return_std
941  */
942  virtual int getSensorProps(const std::string &strKey,
943  std::string &strRadiationType,
944  double &fFoV,
945  double &fBeamDir,
946  double &fMin,
947  double &fMax)
948  {
950  }
951 
952  /*!
953  * \brief Read sensor's identification.
954  *
955  * \param strKey Sensor's unique name id (key).
956  * \param [out] ident Identification structure.
957  *
958  * \copydoc doc_return_std
959  */
960  virtual int readSensorIdentity(const std::string &strKey,
961  VL6180xIdentification &ident)
962  {
964  }
965 
966  /*!
967  * \brief Read sensor's current tuning parameters.
968  *
969  * \param strKey Sensor's unique name id (key).
970  * \param [out] uRangeOffset ToF sensor part-to-part offset.
971  * \param [out] uRangeCrossTalk ToF sensor cross-talk compensation.
972  * \param [out] fAlsGain Ambient light sensor analog gain.
973  * \param [out] uAlsIntPeriod Ambient light sensor integration period
974  * (msec).
975  *
976  * \copydoc doc_return_std
977  */
978  virtual int readSensorTunes(const std::string &strKey,
979  uint_t &uRangeOffset,
980  uint_t &uRangeCrossTalk,
981  double &fAlsGain,
982  uint_t &uAlsIntPeriod)
983  {
985  }
986 
987  protected:
988  laelaps::LaeI2C &m_i2cBus; ///< bound \h_i2c bus instance
989 
990  }; // class LaeRangeInterface
991 
992 
993  // -------------------------------------------------------------------------
994  // LaeVL6180MuxArray Class
995  // -------------------------------------------------------------------------
996 
997  /*!
998  * \brief VL6180 Time of Flight Array Class.
999  *
1000  * This class holds an set of LaeVL6180 objects to manage a VL6180 sensor
1001  * array.
1002  *
1003  * Used in 2.0 hardware.
1004  */
1006  {
1007  public:
1008  static const int AlsFreq = 4; ///< take an ambient measurement cycle rate
1009 
1010  typedef std::vector<sensor::vl6180::LaeVL6180Mux*> VecToFSensors;
1011  ///< time-of-flight sensor vector type
1012 
1013  /*!
1014  * \brief Initialization constructor.
1015  *
1016  * \note The constructor should be kept light weight.
1017  *
1018  * \param i2cbus Bound open \h_i2c bus instance.
1019  */
1021 
1022  /*!
1023  * \brief Destructor.
1024  */
1025  virtual ~LaeVL6180MuxArray();
1026 
1027  /*!
1028  * \brief Get interface version.
1029  *
1030  * \param [out] uVerMajor Interface version major number.
1031  * \param [out] uVerMinor Interface version minor number.
1032  * \param [out] uFwVer Firmware version.
1033  *
1034  * \copydoc doc_return_std
1035  */
1036  virtual int getInterfaceVersion(uint_t &uVerMajor,
1037  uint_t &uVerMinor,
1038  uint_t &uFwVer);
1039 
1040  /*!
1041  * \brief Clear sensed data.
1042  */
1043  virtual void clearSensedData();
1044 
1045  /*!
1046  * \brief Configure sensor array from product description.
1047  *
1048  * \param desc Product description.
1049  *
1050  * \copydoc doc_return_std
1051  */
1052  virtual int configure(const laelaps::LaeDesc &desc);
1053 
1054  /*!
1055  * \brief Configure sensor array from tuning parameters.
1056  *
1057  * \param tunes Tuning parameters.
1058  *
1059  * \copydoc doc_return_std
1060  */
1061  virtual int configure(const laelaps::LaeTunes &tunes);
1062 
1063  /*!
1064  * \brief Reload configuration tuning parameters.
1065  *
1066  * \param tunes Tuning parameters.
1067  *
1068  * \copydoc doc_return_std
1069  */
1070  virtual int reload(const laelaps::LaeTunes &tunes);
1071 
1072  /*!
1073  * \brief Execute task in one cycle to take measurements.
1074  *
1075  * \par Context:
1076  * LaeThreadRange thread instance.
1077  */
1078  virtual void exec();
1079 
1080  /*!
1081  * \brief Get the shadowed range measurement.
1082  *
1083  * The exec() call pulls the measured sensed from the actual sensors.
1084  *
1085  * \param strKey Sensor's unique name (key).
1086  * \param [out] fRange Sensed object range (meters).
1087  *
1088  * \copydoc doc_return_std
1089  */
1090  virtual int getRange(const std::string &strKey, double &fRange);
1091 
1092  /*!
1093  * \brief Get all shadowed sensor range measurements.
1094  *
1095  * The exec() call pulls the measured sensed from the actual sensors.
1096  *
1097  * \param [out] vecNames Vector of sensor unique names.
1098  * \param [out] vecRanges Vector of associated sensor measured ranges
1099  * (meters).
1100  *
1101  * \copydoc doc_return_std
1102  */
1103  virtual int getRange(std::vector<std::string> &vecNames,
1104  std::vector<double> &vecRanges);
1105 
1106  /*!
1107  * \brief Get the shadowed ambient light illuminance measurement.
1108  *
1109  * The exec() call pulls the measured sensed from the actual sensors.
1110  *
1111  * \param strKey Sensor's unique name (key).
1112  * \param [out] fAmbient Sensed ambient light (lux).
1113  *
1114  * \copydoc doc_return_std
1115  */
1116  virtual int getAmbientLight(const std::string &strKey, double &fAmbient);
1117 
1118  /*!
1119  * \brief Get all shadowed sensor ambient light illuminance measurements.
1120  *
1121  * The exec() call pulls the measured sensed from the actual sensors.
1122  *
1123  * \param strKey Sensor's unique name (key).
1124  * \param [out] vecAmbient Vector of associated sensor measured ambients
1125  * (lux).
1126  *
1127  * \copydoc doc_return_std
1128  */
1129  virtual int getAmbientLight(std::vector<std::string> &vecNames,
1130  std::vector<double> &vecAmbient);
1131 
1132  /*!
1133  * \brief Get range sensor properties.
1134  *
1135  * \param strKey Sensor's unique name id (key).
1136  * \param [out] strRadiationType Radiation type.
1137  * \param [out] fFoV Field of View (radians).
1138  * \param [out] fBeamdir Center of beam direction (radians).
1139  * \param [out] fMin Minimum range (meters).
1140  * \param [out] fMax Maximum range (meters).
1141  *
1142  * \copydoc doc_return_std
1143  */
1144  virtual int getSensorProps(const std::string &strKey,
1145  std::string &strRadiationType,
1146  double &fFoV,
1147  double &fBeamDir,
1148  double &fMin,
1149  double &fMax);
1150 
1151  /*!
1152  * \brief Read sensor's identification.
1153  *
1154  * \param strKey Sensor's unique name id (key).
1155  * \param [out] ident Identification structure.
1156  *
1157  * \copydoc doc_return_std
1158  */
1159  virtual int readSensorIdentity(const std::string &strKey,
1160  VL6180xIdentification &ident);
1161 
1162  /*!
1163  * \brief Read sensor's current tuning parameters.
1164  *
1165  * \param strKey Sensor's unique name id (key).
1166  * \param [out] uRangeOffset ToF sensor part-to-part offset.
1167  * \param [out] uRangeCrossTalk ToF sensor cross-talk compensation.
1168  * \param [out] fAlsGain Ambient light sensor analog gain.
1169  * \param [out] uAlsIntPeriod Ambient light sensor integration period
1170  * (msec).
1171  *
1172  * \copydoc doc_return_std
1173  */
1174  virtual int readSensorTunes(const std::string &strKey,
1175  uint_t &uRangeOffset,
1176  uint_t &uRangeCrossTalk,
1177  double &fAlsGain,
1178  uint_t &uAlsIntPeriod);
1179 
1180  protected:
1181  laelaps::LaeI2CMux m_mux; ///< \h_i2c multiplexor
1182  VecToFSensors m_vecToF; ///< time of flight sensors
1183  int m_nAlsIndex; ///< ambient light sensor index
1184  int m_nAlsCounter; ///< when zero, make measurement
1185 
1186  /*
1187  * \brief Find index of sensor key.
1188  *
1189  * \param strKey Sensor's unique name id (key).
1190  *
1191  * \return Returns index if found, -1 otherwise.
1192  */
1193  int keyIndex(const std::string &strKey);
1194 
1195  }; // LaeVL6180MuxArray
1196 
1197 
1198  // -------------------------------------------------------------------------
1199  // LaeRangeMuxSubproc Class
1200  // -------------------------------------------------------------------------
1201 
1202  /*!
1203  * \brief Multiplexed range sensors class.
1204  *
1205  * The interface between the processor and the sensors is through an \h_i2c
1206  * connected sub-processor. Since the sub-processor (mostly) hides the
1207  * specific sensor hardware, this class is more general.
1208  *
1209  * Used in 2.1+ hardware.
1210  */
1212  {
1213  public:
1214  //
1215  // Times
1216  //
1217  static const long TStd = 100; ///< standard wait write_read (usec)
1218 
1219  //
1220  // Types
1221  //
1222  typedef std::map<std::string, LaeVL6180SensorInfo> SensorInfoMap;
1223  ///< Sensor information map type
1224 
1225  /*!
1226  * \brief Initialization constructor.
1227  *
1228  * \note The constructor should be kept light weight.
1229  *
1230  * \param i2cbus Bound open \h_i2c bus instance.
1231  * \param addr ToF multiplexor sub-processor I2C address.
1232  */
1234  uint_t addr=laelaps::LaeI2CAddrToFMux);
1235 
1236  /*!
1237  * \brief Destructor.
1238  */
1239  virtual ~LaeRangeMuxSubproc();
1240 
1241  /*!
1242  * \brief Get interface version.
1243  *
1244  * \param [out] uVerMajor Interface version major number.
1245  * \param [out] uVerMinor Interface version minor number.
1246  * \param [out] uFwVer Firmware version.
1247  *
1248  * \copydoc doc_return_std
1249  */
1250  virtual int getInterfaceVersion(uint_t &uVerMajor,
1251  uint_t &uVerMinor,
1252  uint_t &uFwVer);
1253 
1254  /*!
1255  * \brief Clear sensed data.
1256  */
1257  virtual void clearSensedData();
1258 
1259  /*!
1260  * \brief Configure sensor array from product description.
1261  *
1262  * \param desc Product description.
1263  *
1264  * \copydoc doc_return_std
1265  */
1266  virtual int configure(const laelaps::LaeDesc &desc);
1267 
1268  /*!
1269  * \brief Configure sensor array from tuning parameters.
1270  *
1271  * \param tunes Tuning parameters.
1272  *
1273  * \copydoc doc_return_std
1274  */
1275  virtual int configure(const laelaps::LaeTunes &tunes);
1276 
1277  /*!
1278  * \brief Reload configuration tuning parameters.
1279  *
1280  * \param tunes Tuning parameters.
1281  *
1282  * \copydoc doc_return_std
1283  */
1284  virtual int reload(const laelaps::LaeTunes &tunes);
1285 
1286  /*!
1287  * \brief Execute one cycle to take measurements.
1288  *
1289  * \par Context:
1290  * LaeThreadRange thread instance.
1291  */
1292  virtual void exec();
1293  /*!
1294  * \brief Get a range measurement.
1295  *
1296  * \param strKey Sensor's unique name (key).
1297  * \param [out] fRange Sensed object range (meters).
1298  *
1299  * \copydoc doc_return_std
1300  */
1301  virtual int getRange(const std::string &strKey, double &fRange);
1302 
1303  /*!
1304  * \brief Get all sensor range measurements.
1305  *
1306  * \param [out] vecNames Vector of sensor unique names.
1307  * \param [out] vecRanges Vector of associated sensor measured ranges
1308  * (meters).
1309  *
1310  * \copydoc doc_return_std
1311  */
1312  virtual int getRange(std::vector<std::string> &vecNames,
1313  std::vector<double> &vecRanges);
1314 
1315  /*!
1316  * \brief Get an ambient light illuminance measurement.
1317  *
1318  * \param strKey Sensor's unique name (key).
1319  * \param [out] fAmbient Sensed ambient light (lux).
1320  *
1321  * \copydoc doc_return_std
1322  */
1323  virtual int getAmbientLight(const std::string &strKey, double &fAmbient);
1324 
1325  /*!
1326  * \brief Get all sensor ambient light illuminance measurements.
1327  *
1328  * \param [out] vecNames Vector of sensor unique names.
1329  * \param [out] vecAmbient Vector of associated sensor measured ambients
1330  * (lux).
1331  *
1332  * \copydoc doc_return_std
1333  */
1334  virtual int getAmbientLight(std::vector<std::string> &vecNames,
1335  std::vector<double> &vecAmbient);
1336 
1337  /*!
1338  * \brief Get range sensor properties.
1339  *
1340  * \param strKey Sensor's unique name id (key).
1341  * \param [out] strRadiationType Radiation type.
1342  * \param [out] fFoV Field of View (radians).
1343  * \param [out] fBeamdir Center of beam direction (radians).
1344  * \param [out] fMin Minimum range (meters).
1345  * \param [out] fMax Maximum range (meters).
1346  *
1347  * \copydoc doc_return_std
1348  */
1349  virtual int getSensorProps(const std::string &strKey,
1350  std::string &strRadiationType,
1351  double &fFoV,
1352  double &fBeamDir,
1353  double &fMin,
1354  double &fMax);
1355  /*!
1356  * \brief Read sensor's identification.
1357  *
1358  * \param strKey Sensor's unique name id (key).
1359  * \param [out] ident Identification structure.
1360  *
1361  * \copydoc doc_return_std
1362  */
1363  virtual int readSensorIdentity(const std::string &strKey,
1364  VL6180xIdentification &ident);
1365 
1366  /*!
1367  * \brief Read sensor's current tuning parameters.
1368  *
1369  * \param strKey Sensor's unique name id (key).
1370  * \param [out] uRangeOffset ToF sensor part-to-part offset.
1371  * \param [out] uRangeCrossTalk ToF sensor cross-talk compensation.
1372  * \param [out] fAlsGain Ambient light sensor analog gain.
1373  * \param [out] uAlsIntPeriod Ambient light sensor integration period
1374  * (msec).
1375  *
1376  * \copydoc doc_return_std
1377  */
1378  virtual int readSensorTunes(const std::string &strKey,
1379  uint_t &uRangeOffset,
1380  uint_t &uRangeCrossTalk,
1381  double &fAlsGain,
1382  uint_t &uAlsIntPeriod);
1383 
1384 
1385  protected:
1386  // hardware
1387  uint_t m_addrSubProc; ///< \h_i2c sub-processor address
1388  uint_t m_uFwVer; ///< firmware version number
1389 
1390  // sensor information
1391  SensorInfoMap m_mapInfo; ///< map of sensor properties by key
1392 
1393  // shadow values
1394  std::vector<double> m_vecRanges; ///< measured distances (meters)
1395  std::vector<double> m_vecLux; ///< measured ambient light (lux)
1396 
1397  // mutual exclusion
1398  pthread_mutex_t m_mutex; ///< mutex
1399 
1400  /*!
1401  * \brief Lock the share resource.
1402  *
1403  * The lock()/unlock() primitives provide a thread safe mechanism.
1404  *
1405  * \par Context:
1406  * Any.
1407  */
1408  void lock()
1409  {
1410  pthread_mutex_lock(&m_mutex);
1411  }
1412 
1413  /*!
1414  * \brief Unlock the shared resource.
1415  *
1416  * \par Context:
1417  * Any.
1418  */
1419  void unlock()
1420  {
1421  pthread_mutex_unlock(&m_mutex);
1422  }
1423 
1424 
1425  //........................................................................
1426  // ToFMux Sub-Processor Member Functions
1427  //........................................................................
1428 
1429  /*!
1430  * \brief Get the firmware version command.
1431  *
1432  * \param [out] uVerNum Firmware version number.
1433  *
1434  * \copydoc doc_return_std
1435  */
1436  virtual int cmdGetFwVersion(uint_t &uVerNum);
1437 
1438  /*!
1439  * \brief Read sensor identification command.
1440  *
1441  * \param [out] id Identification structure.
1442  *
1443  * \copydoc doc_return_std
1444  */
1445  int cmdGetIdent(const std::string &strKey, VL6180xIdentification &ident);
1446 
1447  /*!
1448  * \brief Read exported tuning parameters command.
1449  *
1450  * \param [out] uRangeOffset ToF sensor part-to-part offset.
1451  * \param [out] uRangeCrossTalk ToF sensor cross-talk compensation.
1452  * \param [out] fAlsGain Ambient light sensor analog gain.
1453  * \param [out] uAlsIntPeriod Ambient light sensor integration period
1454  * (msec).
1455  *
1456  * \copydoc doc_return_std
1457  */
1458  int cmdGetTunes(const std::string &strKey,
1459  uint_t &uRangeOffset,
1460  uint_t &uRangeCrossTalk,
1461  double &fAlsGain,
1462  uint_t &uAlsIntPeriod);
1463 
1464  /*!
1465  * \brief Get measured object distances.
1466  *
1467  * \param [out] vecRanges Vector of distances (mm).
1468  *
1469  * \copydoc doc_return_std
1470  */
1471  int cmdGetRanges(std::vector<double> &vecRanges);
1472 
1473  /*!
1474  * \brief Get measured ambient light illumination.
1475  *
1476  * \param [out] vecLux Vector of illuminations (lux).
1477  *
1478  * \copydoc doc_return_std
1479  */
1480  int cmdGetAmbientLight(std::vector<double> &vecLux);
1481 
1482  /*!
1483  * \brief Tune time-of-flight range sensor command.
1484  *
1485  * \param uRangeOffset ToF sensor part-to-part offset.
1486  * If VL6180X_FACTORY_DFT then leave as is.
1487  * \param uRangeCrossTalk ToF sensor cross-talk compensation.
1488  * If VL6180X_FACTORY_DFT then leave as is.
1489  *
1490  * \copydoc doc_return_std
1491  */
1492  int cmdTuneToFSensor(const std::string &strKey,
1493  uint_t uRangeOffset,
1494  uint_t uRangeCrossTalk);
1495 
1496  /*!
1497  * \brief Tune ambient light sensor command.
1498  *
1499  * \param fAlsGain Ambient light sensor analog gain.
1500  * \param uAlsIntPeriod Ambient light sensor integration period (msec).
1501  *
1502  * \copydoc doc_return_std
1503  */
1504  int cmdTuneAls(const std::string &strKey,
1505  double fAlsGain,
1506  uint_t uAlsIntPeriod);
1507 
1508 
1509  /*!
1510  * \brief Get range distance measurments command.
1511  *
1512  * \copydoc doc_return_std
1513  */
1514  int cmdGetRanges();
1515 
1516  /*!
1517  * \brief Get ambient light measurments command.
1518  *
1519  * \copydoc doc_return_std
1520  */
1521  int cmdGetAmbientLight();
1522 
1523  }; // class LaeRangeMuxSubproc
1524 
1525 
1526  // -------------------------------------------------------------------------
1527  // LaeRangeSensorGroup Class
1528  // -------------------------------------------------------------------------
1529 
1530  /*!
1531  * \brief Range sensor group class.
1532  *
1533  * Laelaps sensor hardware had major changes between v2.0 and v2.1.
1534  */
1536  {
1537  public:
1538  /*!
1539  * \brief Default constructor.
1540  *
1541  * \param i2cBus I2C interface.
1542  */
1544 
1545  /*!
1546  * \brief Destructor.
1547  */
1549 
1550  /*!
1551  * \brief Black list range sensor group from robot sensors.
1552  */
1553  virtual void blacklist();
1554 
1555  /*!
1556  * \brief White list range sensor group from robot sensors.
1557  */
1558  virtual void whitelist();
1559 
1560  /*!
1561  * \brief Test if range sensor group is black listed.
1562  *
1563  * \return Returns true or false.
1564  */
1565  virtual bool isBlackListed()
1566  {
1567  return m_bBlackListed;
1568  }
1569 
1570  /*!
1571  * \brief Set the interface, given the \h_lae hardware version.
1572  *
1573  * \copydoc doc_return_std
1574  */
1575  int setInterface(uint_t uProdHwVer);
1576 
1577  /*!
1578  * \brief Clear sensed data.
1579  */
1580  void clearSensedData();
1581 
1582  /*!
1583  * \brief Get interface version.
1584  *
1585  * \param [out] uVerMajor Interface version major number.
1586  * \param [out] uVerMinor Interface version minor number.
1587  * \param [out] uFwVer Firmware version.
1588  *
1589  * \copydoc doc_return_std
1590  */
1591  virtual int getInterfaceVersion(uint_t &uVerMajor,
1592  uint_t &uVerMinor,
1593  uint_t &uFwVer);
1594 
1595  /*!
1596  * \brief Configure sensor group from product description.
1597  *
1598  * \param desc Product description.
1599  *
1600  * \copydoc doc_return_std
1601  */
1602  virtual int configure(const laelaps::LaeDesc &desc);
1603 
1604  /*!
1605  * \brief Configure sensor group from tuning parameters.
1606  *
1607  * \param tunes Tuning parameters.
1608  *
1609  * \copydoc doc_return_std
1610  */
1611  virtual int configure(const laelaps::LaeTunes &tunes);
1612 
1613  /*!
1614  * \brief Reload configuration tuning parameters.
1615  *
1616  * \param tunes Tuning parameters.
1617  *
1618  * \copydoc doc_return_std
1619  */
1620  virtual int reload(const laelaps::LaeTunes &tunes);
1621 
1622  /*!
1623  * \brief Get range sensor properties.
1624  *
1625  * \param strKey Sensor's unique name id (key).
1626  * \param [out] strRadiationType Radiation type.
1627  * \param [out] fFoV Field of View (radians).
1628  * \param [out] fBeamdir Center of beam direction (radians).
1629  * \param [out] fMin Minimum range (meters).
1630  * \param [out] fMax Maximum range (meters).
1631  *
1632  * \copydoc doc_return_std
1633  */
1634  virtual int getSensorProps(const std::string &strKey,
1635  std::string &strRadiationType,
1636  double &fFoV,
1637  double &fBeamDir,
1638  double &fMin,
1639  double &fMax);
1640 
1641  /*!
1642  * \brief Read sensor's identification.
1643  *
1644  * \param strKey Sensor's unique name id (key).
1645  * \param [out] ident Identification structure.
1646  *
1647  * \copydoc doc_return_std
1648  */
1649  virtual int readSensorIdentity(const std::string &strKey,
1650  VL6180xIdentification &ident);
1651 
1652  /*!
1653  * \brief Read sensor's current tuning parameters.
1654  *
1655  * \param strKey Sensor's unique name id (key).
1656  * \param [out] uRangeOffset ToF sensor part-to-part offset.
1657  * \param [out] uRangeCrossTalk ToF sensor cross-talk compensation.
1658  * \param [out] fAlsGain Ambient light sensor analog gain.
1659  * \param [out] uAlsIntPeriod Ambient light sensor integration period
1660  * (msec).
1661  *
1662  * \copydoc doc_return_std
1663  */
1664  virtual int readSensorTunes(const std::string &strKey,
1665  uint_t &uRangeOffset,
1666  uint_t &uRangeCrossTalk,
1667  double &fAlsGain,
1668  uint_t &uAlsIntPeriod);
1669 
1670  /*!
1671  * \brief Get the shadowed range measurement.
1672  *
1673  * The exec() call pulls the measured sensed from the actual sensors.
1674  *
1675  * \param strKey Sensor's unique name (key).
1676  * \param [out] fRange Sensed object range (meters).
1677  *
1678  * \copydoc doc_return_std
1679  */
1680  virtual int getRange(const std::string &strKey, double &fRange);
1681 
1682  /*!
1683  * \brief Get all shadowed sensor range measurements.
1684  *
1685  * The exec() call pulls the measured sensed from the actual sensors.
1686  *
1687  * \param [out] vecNames Vector of sensor unique names.
1688  * \param [out] vecRanges Vector of associated sensor measured ranges
1689  * (meters).
1690  *
1691  * \copydoc doc_return_std
1692  */
1693  virtual int getRange(std::vector<std::string> &vecNames,
1694  std::vector<double> &vecRanges);
1695 
1696  /*!
1697  * \brief Get the shadowed ambient light illuminance measurement.
1698  *
1699  * The exec() call pulls the measured sensed from the actual sensors.
1700  *
1701  * \param strKey Sensor's unique name (key).
1702  * \param [out] fAmbient Sensed ambient light (lux).
1703  *
1704  * \copydoc doc_return_std
1705  */
1706  virtual int getAmbientLight(const std::string &strKey, double &fAmbient);
1707 
1708  /*!
1709  * \brief Get all shadowed sensor ambient light illuminance measurements.
1710  *
1711  * The exec() call pulls the measured sensed from the actual sensors.
1712  *
1713  * \param strKey Sensor's unique name (key).
1714  * \param [out] vecAmbient Vector of associated sensor measured ambients
1715  * (lux).
1716  *
1717  * \copydoc doc_return_std
1718  */
1719  virtual int getAmbientLight(std::vector<std::string> &vecNames,
1720  std::vector<double> &vecAmbient);
1721 
1722  /*!
1723  * \brief Execute task in one cycle to take measurements.
1724  *
1725  * \par Context:
1726  * LaeThreadRange thread instance.
1727  */
1728  virtual void exec();
1729 
1730  protected:
1731  laelaps::LaeI2C &m_i2cBus; ///< bound \h_i2c bus instance
1732  LaeRangeInterface *m_interface; ///< the interface
1733  bool m_bBlackListed; ///< sensor group [not] black listed.
1734 
1735  }; // class LaeRangeSensorGroup
1736 
1737  } // namespace vl6180
1738 } // namespace sensor
1739 
1740 
1741 #endif // _LAE_VL6180_H
uint_t m_uAlsIntPeriod
ALS integration period (msec)
Definition: laeVL6180.h:695
pthread_mutex_t m_mutex
mutex
Definition: laeVL6180.h:708
#define VL6180X_RANGE_MAX
maximum range (m)
Definition: laeVL6180.h:131
Multiplexed range sensors class.
Definition: laeVL6180.h:1211
virtual int configure(const laelaps::LaeTunes &tunes)
Configure sensor array from tuning parameters.
Definition: laeVL6180.h:846
void lock()
Lock the share resource.
Definition: laeVL6180.h:718
vl6180x_als_gain
Ambient Light Sensor gain value enumeration.
Definition: laeVL6180.h:247
virtual void exec()
Execute task in one cycle to take measurements.
Definition: laeVL6180.h:869
Laelaps tuning data class.
Definition: laeTune.h:566
actual ALS Gain of 40
Definition: laeVL6180.h:256
std::string getRadiationType()
Get radiation type.
Definition: laeVL6180.h:576
virtual ~LaeRangeInterface()
Destructor.
Definition: laeVL6180.h:796
number of gain enum values
Definition: laeVL6180.h:257
virtual int getInterfaceVersion(uint_t &uVerMajor, uint_t &uVerMinor, uint_t &uFwVer)
Get interface version.
Definition: laeVL6180.h:809
Laelaps robotic mobile platform full description class.
Definition: laeDesc.h:451
void getMinMax(double &fMin, double &fMax)
Get sensor&#39;s minimum and maximum range.
Definition: laeVL6180.h:565
LaeRangeInterface * m_interface
the interface
Definition: laeVL6180.h:1732
double degToRad(double d)
Convert degrees to radians.
Definition: laeUtils.h:124
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
int m_nAlsCounter
when zero, make measurement
Definition: laeVL6180.h:1184
u16_t m_regAlsIntPeriod
ALS itegration period register.
Definition: laeVL6180.h:701
virtual int readSensorIdentity(const std::string &strKey, VL6180xIdentification &ident)
Read sensor&#39;s identification.
Definition: laeVL6180.h:960
laelaps::LaeI2CMux & m_mux
I2C multiplexor.
Definition: laeVL6180.h:684
control register mask
Definition: laeI2CMux.h:100
int m_nAlsIndex
ambient light sensor index
Definition: laeVL6180.h:1183
double m_fAmbientLight
ambient light (lux)
Definition: laeVL6180.h:705
laelaps::LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeVL6180.h:988
void getMeasurements(double &fRange, double &fAmbientLight)
Get last sensed measurements.
Definition: laeVL6180.h:514
double m_fDeadzone
sensor deadzone (m)
Definition: laeVL6180.h:286
virtual int getSensorProps(const std::string &strKey, std::string &strRadiationType, double &fFoV, double &fBeamDir, double &fMin, double &fMax)
Get range sensor properties.
Definition: laeVL6180.h:942
std::string m_strNameId
name identifier of sensor
Definition: laeVL6180.h:688
Container class to hold VL6180 time-of-flight sensor static information.
Definition: laeVL6180.h:280
Laelaps PCA9548A I2C multiplexer switch interface.
double getBeamDir()
Get sensor direction of the center of emitter IR beam.
Definition: laeVL6180.h:545
int m_nChan
multiplexed channel number
Definition: laeVL6180.h:284
VL6180 Time of Flight Class.
Definition: laeVL6180.h:368
virtual int reload(const laelaps::LaeTunes &tunes)
Reload configuration tuning parameters.
Definition: laeVL6180.h:858
byte_t m_regAlsGain
ambient light sensor gain register
Definition: laeVL6180.h:700
std::vector< double > m_vecRanges
measured distances (meters)
Definition: laeVL6180.h:1394
pthread_mutex_t m_mutex
mutex
Definition: laeVL6180.h:1398
int m_nErrorCnt
consecutive error count
Definition: laeVL6180.h:690
void unlock()
Unlock the shared resource.
Definition: laeVL6180.h:1419
actual ALS Gain of 20
Definition: laeVL6180.h:249
double m_fBeamDir
center of beam direction(radians)
Definition: laeVL6180.h:686
std::string m_strDesc
short description
Definition: laeVL6180.h:287
Range sensors interface base class.
Definition: laeVL6180.h:779
std::map< std::string, LaeVL6180SensorInfo > SensorInfoMap
Sensor information map type.
Definition: laeVL6180.h:1222
Laelaps robotic base mobile platform description class interface.
VecToFSensors m_vecToF
time of flight sensors
Definition: laeVL6180.h:1182
std::string getDesc()
Get sensor short description.
Definition: laeVL6180.h:535
Laelaps common utilities.
std::string getNameId()
Get sensor assigned name id.
Definition: laeVL6180.h:525
virtual void clearSensedData()
Clear sensed data.
Definition: laeVL6180.h:823
#define VL6180X_T_AUTO
auto-determine wait time
Definition: laeVL6180.h:169
The sensor namespace.
Definition: laeImu.h:78
actual ALS Gain of 1.72
Definition: laeVL6180.h:253
void lock()
Lock the share resource.
Definition: laeVL6180.h:1408
actual ALS Gain of 1.01
Definition: laeVL6180.h:255
void unlock()
Unlock the shared resource.
Definition: laeVL6180.h:729
Laelaps built-in Time-of-Flight Multiplexer Arduino sub-processor interface.
Laelaps tuning.
double m_fBeamDir
center of beam direction(radians)
Definition: laeVL6180.h:285
double m_fDeadzone
sensor deadzone (m)
Definition: laeVL6180.h:687
int m_nChan
multiplexed channel number
Definition: laeVL6180.h:685
static const int LAE_ECODE_NO_RSRC
no resource available error
Definition: laelaps.h:83
LaeRangeInterface(laelaps::LaeI2C &i2cBus)
Initialization constructor.
Definition: laeVL6180.h:789
double m_fAlsGain
ambient light sensor analog gain
Definition: laeVL6180.h:694
actual ALS Gain of 10.32
Definition: laeVL6180.h:250
uint_t m_uFwVer
firmware version number
Definition: laeVL6180.h:1388
bool m_bBlackListed
sensor group [not] black listed.
Definition: laeVL6180.h:1733
actual ALS Gain of 2.60
Definition: laeVL6180.h:252
actual ALS Gain of 1.28
Definition: laeVL6180.h:254
double getFoV()
Get sensor field of view.
Definition: laeVL6180.h:555
bool m_bBlackListed
sensor is [not] black listed
Definition: laeVL6180.h:691
virtual int readSensorTunes(const std::string &strKey, uint_t &uRangeOffset, uint_t &uRangeCrossTalk, double &fAlsGain, uint_t &uAlsIntPeriod)
Read sensor&#39;s current tuning parameters.
Definition: laeVL6180.h:978
virtual int configure(const laelaps::LaeDesc &desc)
Configure sensor array from product description.
Definition: laeVL6180.h:834
const byte_t LaeI2CAddrToFMux
arduino I2C 7-bit slave address
Definition: laeToFMux.h:117
std::vector< sensor::vl6180::LaeVL6180Mux * > VecToFSensors
time-of-flight sensor vector type
Definition: laeVL6180.h:1010
actual ALS Gain of 5.21
Definition: laeVL6180.h:251
laelaps::LaeI2CMux m_mux
I2C multiplexor.
Definition: laeVL6180.h:1181
u16_t m_regRangeCrossTalk
range cross-talk register
Definition: laeVL6180.h:699
virtual bool isBlackListed()
Test if range sensor group is black listed.
Definition: laeVL6180.h:1565
SensorInfoMap m_mapInfo
map of sensor properties by key
Definition: laeVL6180.h:1391
virtual int getRange(const std::string &strKey, double &fRange)
Get a range measurement.
Definition: laeVL6180.h:881
laelaps::LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeVL6180.h:1731
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeVL6180.h:1387
#define VL6180X_RANGE_MIN
minimum range (m)
Definition: laeVL6180.h:130
virtual int getRange(std::vector< std::string > &vecNames, std::vector< double > &vecRanges)
Get all sensor range measurements.
Definition: laeVL6180.h:895
std::vector< double > m_vecLux
measured ambient light (lux)
Definition: laeVL6180.h:1395
virtual int getAmbientLight(const std::string &strKey, double &fAmbient)
Get an ambient light illuminance measurement.
Definition: laeVL6180.h:909
virtual int getAmbientLight(std::vector< std::string > &vecNames, std::vector< double > &vecAmbient)
Get all sensor ambient light illuminance measurements.
Definition: laeVL6180.h:924
#define VL6180X_RANGE_FOV
field of view (degrees)
Definition: laeVL6180.h:132
double m_fRange
range (m)
Definition: laeVL6180.h:704
std::string m_strDesc
short description
Definition: laeVL6180.h:689
Range sensor group class.
Definition: laeVL6180.h:1535
VL6180 Time of Flight Array Class.
Definition: laeVL6180.h:1005
byte_t m_regRangeOffset
range part-to-part offset register
Definition: laeVL6180.h:698
Top-level package include file.