Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeThreadImu.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // File: laeThreadImu.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 IMU 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 
61 #include "Laelaps/laeImu.h"
62 
63 #include "Laelaps/laeThread.h"
64 #include "Laelaps/laeThreadImu.h"
65 
66 using namespace std;
67 using namespace laelaps;
68 using namespace sensor::imu;
69 
70 //------------------------------------------------------------------------------
71 // LaeThreadImu Class
72 //------------------------------------------------------------------------------
73 
74 const double LaeThreadImu::ThreadImuPrioDft = 80; ///< default priority
75 const double LaeThreadImu::ThreadImuHzDft = 30.0; ///< default run rate
76 
77 LaeThreadImu::LaeThreadImu(LaeImuCleanFlight &hwif) :
78  LaeThread("IMU"), m_hwif(hwif)
79 {
80 }
81 
83 {
84 }
85 
86 int LaeThreadImu::reload(const LaeTunes &tunes)
87 {
88  double fHz;
89  int rc;
90 
91  lock();
92 
93  fHz = tunes.getImuHz();
94 
95  if( fHz != m_fHz )
96  {
97  setHz(fHz);
98  }
99 
100  rc = m_hwif.reload(tunes);
101 
102  unlock();
103 
104  return rc;
105 }
106 
108 {
109  m_hwif.exec();
110 }
virtual void exec()
Execute watchdog task within scheduled cycle.
double getImuHz() const
Get IMU tasks thread cycle rate tune parameter (hertz).
Definition: laeTune.cxx:319
Laelaps thread base class interface.
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
void unlock()
Unlock the I2C bus.
Definition: laeThread.h:235
Laelaps tuning data class.
Definition: laeTune.h:566
virtual ~LaeThreadImu()
Destructor.
void lock()
Lock the I2C bus.
Definition: laeThread.h:221
virtual int reload(const laelaps::LaeTunes &tunes)
Reload with new tuning parameters.
Definition: laeImu.cxx:247
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps common utilities.
Laelaps built-in Inertial Measurement Unit class interface.
Laelaps tuning.
virtual void setHz(const double fHz)
Calculate thread new full cycle run rate.
Definition: laeThread.cxx:214
double m_fHz
thread cycle run rate (Hertz)
Definition: laeThread.h:204
virtual void exec()
Exectute one step to read, convert, and compute IMU values.
Definition: laeImu.cxx:285
Laelaps IMU thread class interface.
sensor::imu::LaeImuCleanFlight & m_hwif
hardware interface
Definition: laeThreadImu.h:105
Top-level package include file.