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 <aspect/blackboard.h>
26#include <aspect/clock.h>
27#include <aspect/configurable.h>
28#include <aspect/logging.h>
29#include <core/threading/thread.h>
30
31namespace fawkes {
32class Mutex;
33class Configuration;
34class Logger;
35class Time;
36class IMUInterface;
37} // namespace fawkes
38
44{
45public:
46 IMUAcquisitionThread(const char * thread_name,
47 bool continuous,
48 const std::string &cfg_name,
49 const std::string &cfg_prefix);
50 virtual ~IMUAcquisitionThread();
51
52 bool lock_if_new_data();
53 void unlock();
54
55 // must be called from sub-classes in continuous case
56 virtual void init();
57 virtual void loop();
58 virtual void finalize();
59
60 /** Get orientation data.
61 * @return orientation data */
62 const float *
64 {
65 return orientation_;
66 }
67
68 /** Get orientation covariance.
69 * @return orientation covariance */
70 const double *
72 {
74 }
75
76 /** Get angular velocity data.
77 * @return angular velocity data */
78 const float *
80 {
81 return angular_velocity_;
82 }
83
84 /** Get angular velocity covariance
85 * @return angular velocity covariance */
86 const double *
88 {
90 }
91
92 /** Get linear acceleration data.
93 * @return linear acceleration data */
94 const float *
96 {
98 }
99
100 /** Get linera acceleration covariance.
101 * @return linear acceleration covariance */
102 const double *
104 {
106 }
107
108 /** Get time of data set.
109 * @return timestamp */
110 const fawkes::Time *
112 {
113 return timestamp_;
114 }
115
116 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
117protected:
118 virtual void
120 {
121 Thread::run();
122 }
123
124protected:
125 std::string cfg_name_;
126 std::string cfg_prefix_;
127 std::string cfg_frame_;
129
132
134
135 float orientation_[4];
141
142private:
143 // only used if continuous
144 fawkes::IMUInterface *imu_if_;
145};
146
147#endif
IMU acqusition thread.
const fawkes::Time * get_timestamp()
Get time of data set.
const float * get_angular_velocity()
Get angular velocity data.
float linear_acceleration_[3]
Pre-allocated linear acceleration as array, 3 entries ordered (x,y,z).
fawkes::Mutex * data_mutex_
Lock while writing to distances or echoes array or marking new data.
std::string cfg_frame_
Coordinate frame for sensor.
const double * get_linear_acceleration_covariance()
Get linera acceleration covariance.
void unlock()
Unlock data,.
double linear_acceleration_covariance_[9]
Pre-allocated linear acceleration covariance, row major matrix ordered x, y, z.
IMUAcquisitionThread(const char *thread_name, bool continuous, const std::string &cfg_name, const std::string &cfg_prefix)
Constructor.
double angular_velocity_covariance_[9]
Pre-allocated angular velocity covariance, row major matrix ordered x, y, z.
double orientation_covariance_[9]
Pre-allocated orientation covariance, row major matrix ordered x, y, z.
virtual void loop()
Code to execute in the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
float orientation_[4]
Pre-allocated orientation quaternion as array, 4 entries ordered (x,y,z,w).
bool lock_if_new_data()
Lock data if fresh.
const float * get_orientation()
Get orientation data.
virtual void finalize()
Finalize the thread.
const double * get_angular_velocity_covariance()
Get angular velocity covariance.
std::string cfg_prefix_
Configuration path prefix.
bool cfg_continuous_
True if running continuous.
const double * get_orientation_covariance()
Get orientation covariance.
const float * get_linear_acceleration()
Get linear acceleration data.
std::string cfg_name_
Configuration name (third element in config path).
float angular_velocity_[3]
Pre-allocated angular velocities as array, 3 entries ordered (x,y,z).
bool new_data_
Set to true in your loop if new data is available.
virtual void init()
Initialize the thread.
fawkes::Time * timestamp_
Time when the most recent data was received.
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:34
Thread aspect to access configuration data.
Definition: configurable.h:33
IMUInterface Fawkes BlackBoard Interface.
Definition: IMUInterface.h:34
Thread aspect to log output.
Definition: logging.h:33
Mutex mutual exclusion lock.
Definition: mutex.h:33
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93
Fawkes library namespace.