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 <core/threading/thread.h>
27 #include <aspect/logging.h>
28 #include <aspect/configurable.h>
29 #include <aspect/clock.h>
30 
31 namespace fawkes {
32  class Mutex;
33  class Configuration;
34  class Logger;
35 }
36 
38 : public fawkes::Thread,
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  fawkes::Logger *logger) = 0;
52 
53  const float * get_distance_data();
54  const float * get_echo_data();
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: virtual void run() { Thread::run(); }
61 
62  protected:
63  void alloc_distances(unsigned int num_distances);
64  void alloc_echoes(unsigned int num_echoes);
65 
66  protected:
68 
69  bool _new_data;
70  float *_distances;
71  float *_echoes;
72 
73  unsigned int _distances_size;
74  unsigned int _echoes_size;
75 
76 };
77 
78 
79 #endif
unsigned int get_distance_data_size()
Get distance data size.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Laser acqusition thread.
Fawkes library namespace.
virtual void pre_init(fawkes::Configuration *config, fawkes::Logger *logger)=0
Pre initialization.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
void alloc_distances(unsigned int num_distances)
Allocate distances array.
fawkes::Mutex * _data_mutex
Lock while writing to distances or echoes array or marking new data.
unsigned int get_echo_data_size()
Get echo data size.
unsigned int _distances_size
Assign this the size of the _distances array.
LaserAcquisitionThread(const char *thread_name)
Constructor.
float * _distances
Allocate a float array and copy your distance values measured in meters here.
const float * get_distance_data()
Get distance data.
Thread aspect to log output.
Definition: logging.h:35
unsigned int _echoes_size
Assign this the size of the _echoes array.
void unlock()
Unlock data,.
bool _new_data
Set to true in your loop if new data is available.
Thread aspect to access configuration data.
Definition: configurable.h:35
void alloc_echoes(unsigned int num_echoes)
Allocate echoes array.
Mutex mutual exclusion lock.
Definition: mutex.h:32
bool lock_if_new_data()
Lock data if fresh.
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:44
Interface for configuration handling.
Definition: config.h:63
const float * get_echo_data()
Get echo data.
float * _echoes
Allocate a float array and copy your echo values here.
virtual void run()
Stub to see name in backtrace for easier debugging.
Interface for logging.
Definition: logger.h:34