Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeThreadKin.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // File: laeThreadKin.cxx
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2016-02-08 16:43:26 -0700 (Mon, 08 Feb 2016) $
10  * $Rev: 4307 $
11  *
12  * \brief Laelaps kinodynamics 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/laeKin.h"
62 
63 #include "Laelaps/laeThread.h"
64 #include "Laelaps/laeThreadKin.h"
65 
66 using namespace std;
67 using namespace laelaps;
68 
69 //------------------------------------------------------------------------------
70 // LaeThreadKin Class
71 //------------------------------------------------------------------------------
72 
73 const double LaeThreadKin::ThreadKinPrioDft = 99;
74 const double LaeThreadKin::ThreadKinHzDft = 30.0;
75 const long LaeThreadKin::ThreadKinTHealthDft = 5;
76 
77 LaeThreadKin::LaeThreadKin(LaeKinematics &kin) :
78  LaeThread("Kinodynamics"), m_kin(kin)
79 {
80  m_bWaitOneCycle = false;
81 }
82 
84 {
85 }
86 
87 int LaeThreadKin::reload(const LaeTunes &tunes)
88 {
89  double fHz;
90  int rc;
91 
92  lock();
93 
94  fHz = tunes.getKinematicsHz();
95 
96  if( fHz != m_fHz )
97  {
98  setHz(fHz);
99  }
100 
101  rc = m_kin.reload(tunes);
102 
103  unlock();
104 
105  return rc;
106 }
107 
109 {
110  lock();
111 
112  m_bWaitOneCycle = true;
113 
114  pthread_cond_wait(&m_condSync, &m_mutexSync);
115 
116  unlock();
117 }
118 
120 {
122 }
123 
125 {
126  m_kin.exec();
127 
128  // time to monitor health
130  {
134  }
135 
136  // caller blocked waiting one execution cycle - signal to unblock
137  if( m_bWaitOneCycle )
138  {
139  m_bWaitOneCycle = false;
140  pthread_cond_signal(&m_condSync);
141  }
142 }
Laelaps thread base class interface.
Laelaps kinodynamics thread class interface.
void unlock()
Unlock the I2C bus.
Definition: laeThread.h:235
Laelaps tuning data class.
Definition: laeTune.h:566
double getKinematicsHz() const
Get kinematics thread cycle rate tune parameter (hertz).
Definition: laeTune.cxx:324
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: laeThread.h:198
Laelaps kinematics class.
Definition: laeKin.h:119
void lock()
Lock the I2C bus.
Definition: laeThread.h:221
virtual void exec()
Execute kinematics task(s).
Definition: laeKin.cxx:1600
virtual void exec()
Execute watchdog task within scheduled cycle.
bool m_bWaitOneCycle
[not] waiting for one cycle
Definition: laeThreadKin.h:116
struct timespec m_tsExecThis
start of this execution time stamp
Definition: laeThread.h:210
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
virtual ~LaeThreadKin()
Destructor.
virtual void transToRunning()
Ready to Running state transition function.
Laelaps common utilities.
LaeKinematics & m_kin
kinematics interface
Definition: laeThreadKin.h:115
The Laelaps kinematics and dynamics 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
struct timespec m_tsSchedHealth
working health scheduler time stamp
Definition: laeThreadKin.h:117
virtual void waitOneCycle()
Force calling thread to wait one full execution cycle.
pthread_cond_t m_condSync
synchonization condition
Definition: laeThread.h:199
virtual int reload(const LaeTunes &tunes)
Reload configuration tuning parameters.
Definition: laeKin.cxx:897
static const long ThreadKinTHealthDft
monitor health period
Definition: laeThreadKin.h:87
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
virtual int monitorHealth()
Monitor kinematics health.
Definition: laeKin.cxx:1551
Top-level package include file.