Fawkes API  Fawkes Development Version
acquisition_thread.h
00001 
00002 /***************************************************************************
00003  *  acquisition_thread.h - Thread that retrieves the laser data
00004  *
00005  *  Created: Wed Oct 08 13:41:02 2008
00006  *  Copyright  2006-2008  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_ACQUISITION_THREAD_H_
00024 #define __PLUGINS_LASER_ACQUISITION_THREAD_H_
00025 
00026 #include <core/threading/thread.h>
00027 #include <aspect/logging.h>
00028 #include <aspect/configurable.h>
00029 #include <aspect/clock.h>
00030 
00031 namespace fawkes {
00032   class Mutex;
00033   class Configuration;
00034   class Logger;
00035 }
00036 
00037 class LaserAcquisitionThread
00038 : public fawkes::Thread,
00039   public fawkes::LoggingAspect,
00040   public fawkes::ConfigurableAspect,
00041   public fawkes::ClockAspect
00042 {
00043  public:
00044   LaserAcquisitionThread(const char *thread_name);
00045   virtual ~LaserAcquisitionThread();
00046 
00047   bool lock_if_new_data();
00048   void unlock();
00049 
00050   virtual void   pre_init(fawkes::Configuration *config,
00051                           fawkes::Logger *logger) = 0;
00052 
00053   const float *  get_distance_data();
00054   const float *  get_echo_data();
00055 
00056   unsigned int   get_distance_data_size();
00057   unsigned int   get_echo_data_size();
00058 
00059  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00060  protected: virtual void run() { Thread::run(); }
00061 
00062  protected:
00063   void alloc_distances(unsigned int num_distances);
00064   void alloc_echoes(unsigned int num_echoes);
00065 
00066  protected:
00067   fawkes::Mutex    *_data_mutex;
00068 
00069   bool    _new_data;
00070   float  *_distances;
00071   float  *_echoes;
00072 
00073   unsigned int  _distances_size;
00074   unsigned int  _echoes_size;
00075 
00076 };
00077 
00078 
00079 #endif