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  class Time;
36 }
37 
39 : public fawkes::Thread,
40  public fawkes::LoggingAspect,
42  public fawkes::ClockAspect
43 {
44  public:
45  LaserAcquisitionThread(const char *thread_name);
46  virtual ~LaserAcquisitionThread();
47 
48  bool lock_if_new_data();
49  void unlock();
50 
51  virtual void pre_init(fawkes::Configuration *config,
52  fawkes::Logger *logger) = 0;
53 
54  const float * get_distance_data();
55  const float * get_echo_data();
56  const fawkes::Time * get_timestamp();
57 
58  unsigned int get_distance_data_size();
59  unsigned int get_echo_data_size();
60 
61  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
62  protected: virtual void run() { Thread::run(); }
63 
64  protected:
65  void alloc_distances(unsigned int num_distances);
66  void alloc_echoes(unsigned int num_echoes);
67  void reset_distances();
68  void reset_echoes();
69 
70  protected:
73 
74  bool _new_data;
75  float *_distances;
76  float *_echoes;
77 
78  unsigned int _distances_size;
79  unsigned int _echoes_size;
80 
81 };
82 
83 
84 #endif
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Laser acqusition thread.
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
A class for handling time.
Definition: time.h:91
Thread class encapsulation of pthreads.
Definition: thread.h:42
fawkes::Time * _timestamp
Time when the most recent data was received.
fawkes::Mutex * _data_mutex
Lock while writing to distances or echoes array or marking new data.
unsigned int _distances_size
Assign this the size of the _distances array.
float * _distances
Allocate a float array and copy your distance values measured in meters here.
Thread aspect to log output.
Definition: logging.h:35
unsigned int _echoes_size
Assign this the size of the _echoes array.
bool _new_data
Set to true in your loop if new data is available.
Thread aspect to access configuration data.
Definition: configurable.h:35
Mutex mutual exclusion lock.
Definition: mutex.h:32
Interface for configuration handling.
Definition: config.h:67
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