Fawkes API  Fawkes Development Version
acquisition_thread.h
1 
2 /***************************************************************************
3  * acquisition_thread.h - Thread that retrieves the laser data
4  *
5  * Created: Wed Oct 08 13:41:02 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _PLUGINS_LASER_ACQUISITION_THREAD_H_
24 #define _PLUGINS_LASER_ACQUISITION_THREAD_H_
25 
26 #include <aspect/clock.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <core/threading/thread.h>
30 
31 namespace fawkes {
32 class Mutex;
33 class Configuration;
34 class Logger;
35 class Time;
36 } // namespace fawkes
37 
39  public fawkes::LoggingAspect,
41  public fawkes::ClockAspect
42 {
43 public:
44  LaserAcquisitionThread(const char *thread_name);
45  virtual ~LaserAcquisitionThread();
46 
47  bool lock_if_new_data();
48  void unlock();
49 
51 
52  const float * get_distance_data();
53  const float * get_echo_data();
54  const fawkes::Time *get_timestamp();
55 
56  unsigned int get_distance_data_size();
57  unsigned int get_echo_data_size();
58 
59  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
60 protected:
61  virtual void
62  run()
63  {
64  Thread::run();
65  }
66 
67 protected:
68  void alloc_distances(unsigned int num_distances);
69  void alloc_echoes(unsigned int num_echoes);
70  void reset_distances();
71  void reset_echoes();
72 
73 protected:
76 
77  bool _new_data;
78  float *_distances;
79  float *_echoes;
80 
81  unsigned int _distances_size;
82  unsigned int _echoes_size;
83 };
84 
85 #endif
LaserAcquisitionThread::alloc_echoes
void alloc_echoes(unsigned int num_echoes)
Allocate echoes array.
Definition: acquisition_thread.cpp:190
LaserAcquisitionThread
Laser acqusition thread.
Definition: acquisition_thread.h:42
fawkes::Mutex
Mutex mutual exclusion lock.
Definition: mutex.h:33
LaserAcquisitionThread::_distances_size
unsigned int _distances_size
Assign this the size of the _distances array.
Definition: acquisition_thread.h:81
LaserAcquisitionThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: acquisition_thread.h:62
LaserAcquisitionThread::unlock
void unlock()
Unlock data,.
Definition: acquisition_thread.cpp:116
LaserAcquisitionThread::alloc_distances
void alloc_distances(unsigned int num_distances)
Allocate distances array.
Definition: acquisition_thread.cpp:174
LaserAcquisitionThread::_data_mutex
fawkes::Mutex * _data_mutex
Lock while writing to distances or echoes array or marking new data.
Definition: acquisition_thread.h:74
LaserAcquisitionThread::_echoes
float * _echoes
Allocate a float array and copy your echo values here.
Definition: acquisition_thread.h:79
LaserAcquisitionThread::_timestamp
fawkes::Time * _timestamp
Time when the most recent data was received.
Definition: acquisition_thread.h:75
LaserAcquisitionThread::get_distance_data
const float * get_distance_data()
Get distance data.
Definition: acquisition_thread.cpp:125
fawkes::Configuration
Interface for configuration handling.
Definition: config.h:65
LaserAcquisitionThread::reset_distances
void reset_distances()
Reset all distance values to NaN.
Definition: acquisition_thread.cpp:202
LaserAcquisitionThread::_new_data
bool _new_data
Set to true in your loop if new data is available.
Definition: acquisition_thread.h:77
LaserAcquisitionThread::get_echo_data
const float * get_echo_data()
Get echo data.
Definition: acquisition_thread.cpp:135
fawkes::LoggingAspect::logger
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
fawkes::Logger
Interface for logging.
Definition: logger.h:42
fawkes
Fawkes library namespace.
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
LaserAcquisitionThread::lock_if_new_data
bool lock_if_new_data()
Lock data if fresh.
Definition: acquisition_thread.cpp:103
LaserAcquisitionThread::_echoes_size
unsigned int _echoes_size
Assign this the size of the _echoes array.
Definition: acquisition_thread.h:82
LaserAcquisitionThread::_distances
float * _distances
Allocate a float array and copy your distance values measured in meters here.
Definition: acquisition_thread.h:78
fawkes::ConfigurableAspect::config
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:41
fawkes::Time
A class for handling time.
Definition: time.h:93
LaserAcquisitionThread::reset_echoes
void reset_echoes()
Reset all distance values to NaN.
Definition: acquisition_thread.cpp:217
LaserAcquisitionThread::get_timestamp
const fawkes::Time * get_timestamp()
Get timestamp of data.
Definition: acquisition_thread.cpp:163
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
LaserAcquisitionThread::LaserAcquisitionThread
LaserAcquisitionThread(const char *thread_name)
Constructor.
Definition: acquisition_thread.cpp:78
LaserAcquisitionThread::pre_init
virtual void pre_init(fawkes::Configuration *config, fawkes::Logger *logger)=0
Pre initialization.
LaserAcquisitionThread::get_echo_data_size
unsigned int get_echo_data_size()
Get echo data size.
Definition: acquisition_thread.cpp:154
fawkes::ConfigurableAspect
Thread aspect to access configuration data.
Definition: configurable.h:33
fawkes::ClockAspect
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
LaserAcquisitionThread::get_distance_data_size
unsigned int get_distance_data_size()
Get distance data size.
Definition: acquisition_thread.cpp:145