Fawkes API  Fawkes Development Version
acquisition_thread.h
1 
2 /***************************************************************************
3  * acquisition_thread.h - Thread that retrieves IMU data
4  *
5  * Created: Sun Jun 22 21:16:03 2014
6  * Copyright 2006-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef __PLUGINS_IMU_ACQUISITION_THREAD_H_
23 #define __PLUGINS_IMU_ACQUISITION_THREAD_H_
24 
25 #include <core/threading/thread.h>
26 #include <aspect/logging.h>
27 #include <aspect/configurable.h>
28 #include <aspect/clock.h>
29 #include <aspect/blackboard.h>
30 
31 namespace fawkes {
32  class Mutex;
33  class Configuration;
34  class Logger;
35  class Time;
36  class IMUInterface;
37 }
38 
40 : public fawkes::Thread,
41  public fawkes::LoggingAspect,
43  public fawkes::ClockAspect,
45 {
46  public:
47  IMUAcquisitionThread(const char *thread_name, bool continuous,
48  std::string &cfg_name, std::string &cfg_prefix);
49  virtual ~IMUAcquisitionThread();
50 
51  bool lock_if_new_data();
52  void unlock();
53 
54  // must be called from sub-classes in continuous case
55  virtual void init();
56  virtual void loop();
57  virtual void finalize();
58 
59  /** Get orientation data.
60  * @return orientation data */
61  const float * get_orientation()
62  { return orientation_; }
63 
64  /** Get orientation covariance.
65  * @return orientation covariance */
66  const double * get_orientation_covariance()
67  { return orientation_covariance_; }
68 
69  /** Get angular velocity data.
70  * @return angular velocity data */
71  const float * get_angular_velocity()
72  { return angular_velocity_; }
73 
74  /** Get angular velocity covariance
75  * @return angular velocity covariance */
77  { return angular_velocity_covariance_; }
78 
79  /** Get linear acceleration data.
80  * @return linear acceleration data */
81  const float * get_linear_acceleration()
82  { return linear_acceleration_; }
83 
84  /** Get linera acceleration covariance.
85  * @return linear acceleration covariance */
87  { return linear_acceleration_covariance_; }
88 
89  /** Get time of data set.
90  * @return timestamp */
92  { return timestamp_; }
93 
94  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
95  protected: virtual void run() { Thread::run(); }
96 
97  protected:
98  std::string cfg_name_;
99  std::string cfg_prefix_;
100  std::string cfg_frame_;
102 
105 
106  bool new_data_;
107 
108  float orientation_[4];
109  double orientation_covariance_[9];
110  float angular_velocity_[3];
111  double angular_velocity_covariance_[9];
112  float linear_acceleration_[3];
113  double linear_acceleration_covariance_[9];
114 
115  private:
116  // only used if continuous
117  fawkes::IMUInterface *imu_if_;
118 
119 };
120 
121 
122 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
const double * get_orientation_covariance()
Get orientation covariance.
Fawkes library namespace.
const float * get_linear_acceleration()
Get linear acceleration data.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
std::string cfg_name_
Configuration name (third element in config path).
IMU acqusition thread.
A class for handling time.
Definition: time.h:91
fawkes::Time * timestamp_
Time when the most recent data was received.
Thread class encapsulation of pthreads.
Definition: thread.h:42
const float * get_angular_velocity()
Get angular velocity data.
const float * get_orientation()
Get orientation data.
bool new_data_
Set to true in your loop if new data is available.
std::string cfg_frame_
Coordinate frame for sensor.
std::string cfg_prefix_
Configuration path prefix.
const double * get_angular_velocity_covariance()
Get angular velocity covariance.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35
IMUInterface Fawkes BlackBoard Interface.
Definition: IMUInterface.h:33
virtual void run()
Stub to see name in backtrace for easier debugging.
fawkes::Mutex * data_mutex_
Lock while writing to distances or echoes array or marking new data.
bool cfg_continuous_
True if running continuous.
Mutex mutual exclusion lock.
Definition: mutex.h:32
const double * get_linear_acceleration_covariance()
Get linera acceleration covariance.
const fawkes::Time * get_timestamp()
Get time of data set.