Fawkes API  Fawkes Development Version
filter_thread.h
00001 
00002 /***************************************************************************
00003  *  filter_thread.h - Thread to filter laser data
00004  *
00005  *  Created: Sun Mar 13 01:11:11 2011
00006  *  Copyright  2006-2011  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __PLUGINS_LASER_FILTER_FILTER_THREAD_H_
00024 #define __PLUGINS_LASER_FILTER_FILTER_THREAD_H_
00025 
00026 #include "filters/filter.h"
00027 
00028 #include <core/threading/thread.h>
00029 #include <aspect/blocked_timing.h>
00030 #include <aspect/logging.h>
00031 #include <aspect/configurable.h>
00032 #include <aspect/blackboard.h>
00033 #ifdef HAVE_TF
00034 #  include <aspect/tf.h>
00035 #endif
00036 
00037 #include <string>
00038 #include <list>
00039 #include <vector>
00040 
00041 namespace fawkes {
00042   class Laser360Interface;
00043   class Laser720Interface;
00044 }
00045 
00046 class LaserFilterThread
00047 : public fawkes::Thread,
00048   public fawkes::BlockedTimingAspect,
00049   public fawkes::LoggingAspect,
00050   public fawkes::ConfigurableAspect,
00051 #ifdef HAVE_TF
00052   public fawkes::TransformAspect,
00053 #endif
00054   public fawkes::BlackBoardAspect
00055 {
00056  public:
00057   LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix);
00058 
00059   virtual void init();
00060   virtual void finalize();
00061   virtual void loop();
00062 
00063   void wait_done();
00064 
00065   void set_wait_threads(std::list<LaserFilterThread *> &threads);
00066   void set_wait_barrier(fawkes::Barrier *barrier);
00067 
00068  private:
00069   /// @cond INTERNALS
00070   typedef struct {
00071     bool               is_360;
00072     std::string        id;
00073     union {
00074       fawkes::Laser360Interface *as360;
00075       fawkes::Laser720Interface *as720;
00076     } interface_typed;
00077     fawkes::Interface *interface;
00078   } LaserInterface;
00079   /// @endcond
00080 
00081   void open_interfaces(std::string prefix, std::vector<LaserInterface> &ifs,
00082                        std::vector<LaserDataFilter::Buffer *> &bufs, bool writing);
00083 
00084   LaserDataFilter *  create_filter(std::string filter_type, std::string prefix,
00085                                    unsigned int in_data_size,
00086                                    std::vector<LaserDataFilter::Buffer *> &inbufs);
00087 
00088 
00089  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00090  protected: virtual void run() { Thread::run(); }
00091 
00092  private:
00093   std::vector<LaserInterface> __in;
00094   std::vector<LaserInterface> __out;
00095 
00096   std::vector<LaserDataFilter::Buffer *>  __in_bufs;
00097   std::vector<LaserDataFilter::Buffer *>  __out_bufs;
00098 
00099   LaserDataFilter *__filter;
00100 
00101   unsigned int     __num_values;
00102 
00103   std::string      __cfg_name;
00104   std::string      __cfg_prefix;
00105 
00106 
00107 
00108   std::list<LaserFilterThread *>  __wait_threads;
00109   bool                            __wait_done;
00110   fawkes::Mutex                  *__wait_mutex;
00111   fawkes::WaitCondition          *__wait_cond;
00112   fawkes::Barrier                *__wait_barrier;
00113 };
00114 
00115 
00116 #endif