Fawkes API  Fawkes Development Version
filter_thread.h
1 
2 /***************************************************************************
3  * filter_thread.h - Thread to filter laser data
4  *
5  * Created: Sun Mar 13 01:11:11 2011
6  * Copyright 2006-2011 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_FILTER_FILTER_THREAD_H_
24 #define __PLUGINS_LASER_FILTER_FILTER_THREAD_H_
25 
26 #include "filters/filter.h"
27 
28 #include <core/threading/thread.h>
29 #include <aspect/blocked_timing.h>
30 #include <aspect/logging.h>
31 #include <aspect/configurable.h>
32 #include <aspect/blackboard.h>
33 #ifdef HAVE_TF
34 # include <aspect/tf.h>
35 #endif
36 
37 #include <string>
38 #include <list>
39 #include <vector>
40 
41 namespace fawkes {
42  class Laser360Interface;
43  class Laser720Interface;
44 }
45 
47 : public fawkes::Thread,
49  public fawkes::LoggingAspect,
51 #ifdef HAVE_TF
53 #endif
55 {
56  public:
57  LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix);
58 
59  virtual void init();
60  virtual void finalize();
61  virtual void loop();
62 
63  void wait_done();
64 
65  void set_wait_threads(std::list<LaserFilterThread *> &threads);
66  void set_wait_barrier(fawkes::Barrier *barrier);
67 
68  private:
69  /// @cond INTERNALS
70  typedef struct {
71  bool is_360;
72  std::string id;
73  union {
76  } interface_typed;
77  fawkes::Interface *interface;
78  } LaserInterface;
79  /// @endcond
80 
81  void open_interfaces(std::string prefix, std::vector<LaserInterface> &ifs,
82  std::vector<LaserDataFilter::Buffer *> &bufs, bool writing);
83 
84  LaserDataFilter * create_filter(std::string filter_type, std::string prefix,
85  unsigned int in_data_size,
86  std::vector<LaserDataFilter::Buffer *> &inbufs);
87 
88 
89  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
90  protected: virtual void run() { Thread::run(); }
91 
92  private:
93  std::vector<LaserInterface> __in;
94  std::vector<LaserInterface> __out;
95 
96  std::vector<LaserDataFilter::Buffer *> __in_bufs;
97  std::vector<LaserDataFilter::Buffer *> __out_bufs;
98 
99  LaserDataFilter *__filter;
100 
101  unsigned int __num_values;
102 
103  std::string __cfg_name;
104  std::string __cfg_prefix;
105 
106 
107 
108  std::list<LaserFilterThread *> __wait_threads;
109  bool __wait_done;
110  fawkes::Mutex *__wait_mutex;
111  fawkes::WaitCondition *__wait_cond;
112  fawkes::Barrier *__wait_barrier;
113 };
114 
115 
116 #endif
Laser360Interface Fawkes BlackBoard Interface.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: filter_thread.h:90
void set_wait_threads(std::list< LaserFilterThread * > &threads)
Set threads to wait for in loop.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Wait until a given condition holds.
virtual void finalize()
Finalize the thread.
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Thread aspect to access the transform system.
Definition: tf.h:38
void set_wait_barrier(fawkes::Barrier *barrier)
Set wait barrier.
Thread aspect to use blocked timing.
LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix)
Constructor.
Thread aspect to log output.
Definition: logging.h:35
Laser filter thread.
Definition: filter_thread.h:46
Thread aspect to access configuration data.
Definition: configurable.h:35
void wait_done()
Wait until thread is done.
virtual void init()
Initialize the thread.
Mutex mutual exclusion lock.
Definition: mutex.h:32
Laser720Interface Fawkes BlackBoard Interface.
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
Definition: barrier.h:32
virtual void loop()
Code to execute in the thread.
Laser data filter.
Definition: filter.h:28