Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeThreadRange.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // File: laeThreadRange.cxx
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2015-08-07 14:25:35 -0600 (Fri, 07 Aug 2015) $
10  * $Rev: 4051 $
11  *
12  * \brief Laelaps watchdog thread class implementation.
13  *
14  * \author Robin Knight (robin.knight@roadnarrows.com)
15  *
16  * \par Copyright
17  * \h_copy 2015-2018. RoadNarrows LLC.\n
18  * http://www.roadnarrows.com\n
19  * All Rights Reserved
20  */
21 /*
22  * @EulaBegin@
23  *
24  * Unless otherwise stated explicitly, all materials contained are copyrighted
25  * and may not be used without RoadNarrows LLC's written consent,
26  * except as provided in these terms and conditions or in the copyright
27  * notice (documents and software) or other proprietary notice provided with
28  * the relevant materials.
29  *
30  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
31  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
32  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
33  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
34  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
35  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
38  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
39  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
40  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
41  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
42  *
43  * @EulaEnd@
44  */
45 ////////////////////////////////////////////////////////////////////////////////
46 
47 #include <sys/types.h>
48 #include <sys/time.h>
49 #include <time.h>
50 #include <pthread.h>
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/log.h"
56 
57 #include "Laelaps/laelaps.h"
58 #include "Laelaps/laeUtils.h"
59 #include "Laelaps/laeTune.h"
60 #include "Laelaps/laeDb.h"
61 
62 #include "Laelaps/laeVL6180.h"
63 
64 #include "Laelaps/laeThread.h"
65 #include "Laelaps/laeThreadRange.h"
66 
67 using namespace std;
68 using namespace laelaps;
69 using namespace sensor::vl6180;
70 
71 //------------------------------------------------------------------------------
72 // LaeThreadRange Class
73 //------------------------------------------------------------------------------
74 
75 const double LaeThreadRange::ThreadRangePrioDft = 75; ///< default priority
76 const double LaeThreadRange::ThreadRangeHzDft = 8.0; ///< default run rate
77 
78 LaeThreadRange::LaeThreadRange(LaeRangeSensorGroup &hwif) :
79  LaeThread("Range"), m_hwif(hwif)
80 {
81  m_iSensor = 0;
82 }
83 
85 {
86 }
87 
89 {
90  double fHz;
91  int rc;
92 
93  lock();
94 
95  fHz = tunes.getRangeHz();
96 
97  if( fHz != m_fHz )
98  {
99  setHz(fHz);
100  }
101 
102  rc = m_hwif.reload(tunes);
103 
104  unlock();
105 
106  return rc;
107 }
108 
110 {
111  m_hwif.exec();
112 }
Laelaps thread base class interface.
void unlock()
Unlock the I2C bus.
Definition: laeThread.h:235
Laelaps tuning data class.
Definition: laeTune.h:566
virtual int reload(const laelaps::LaeTunes &tunes)
Reload configuration tuning parameters.
Definition: laeVL6180.cxx:2425
size_t m_iSensor
next scheduled sensor index
void lock()
Lock the I2C bus.
Definition: laeThread.h:221
sensor::vl6180::LaeRangeSensorGroup & m_hwif
hardware interface
virtual void exec()
Execute task in one cycle to take measurements.
Definition: laeVL6180.cxx:2513
Laelaps Time-of-Flight sensors. The ToFs are used as a virtual bumper for close-in obstacle detection...
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
virtual void exec()
Execute watchdog task within scheduled cycle.
Laelaps common utilities.
Laelaps tuning.
virtual void setHz(const double fHz)
Calculate thread new full cycle run rate.
Definition: laeThread.cxx:214
Laelaps range sensors thread class interface.
double m_fHz
thread cycle run rate (Hertz)
Definition: laeThread.h:204
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
virtual ~LaeThreadRange()
Destructor.
double getRangeHz() const
Get range sensing thread cycle rate tune parameter (hertz).
Definition: laeTune.cxx:329
Laelaps real-time "database".
Range sensor group class.
Definition: laeVL6180.h:1535
Top-level package include file.