Fawkes API  Fawkes Development Version
image_thread.h
00001 
00002 /***************************************************************************
00003  *  image_thread.cpp - Thread to exchange point clouds
00004  *
00005  *  Created: Tue Apr 10 22:12:27 2012
00006  *  Copyright  2011-2012  Tim Niemueller [www.niemueller.de]
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU Library General Public License for more details.
00018  *
00019  *  Read the full text in the LICENSE.GPL file in the doc directory.
00020  */
00021 
00022 #ifndef __PLUGINS_ROS_IMAGE_THREAD_H_
00023 #define __PLUGINS_ROS_IMAGE_THREAD_H_
00024 
00025 #include <core/threading/thread.h>
00026 #include <aspect/blocked_timing.h>
00027 #include <aspect/clock.h>
00028 #include <aspect/configurable.h>
00029 #include <aspect/logging.h>
00030 #include <aspect/pointcloud.h>
00031 #include <plugins/ros/aspect/ros.h>
00032 #include <core/threading/mutex.h>
00033 
00034 #include <list>
00035 #include <queue>
00036 
00037 #include <ros/node_handle.h>
00038 #include <image_transport/image_transport.h>
00039 #include <sensor_msgs/Image.h>
00040 
00041 namespace firevision {
00042   class SharedMemoryImageBuffer;
00043 }
00044 
00045 class RosImagesThread
00046 : public fawkes::Thread,
00047   public fawkes::ClockAspect,
00048   public fawkes::LoggingAspect,
00049   public fawkes::ConfigurableAspect,
00050   public fawkes::BlockedTimingAspect,
00051   public fawkes::ROSAspect
00052 {
00053  public:
00054   RosImagesThread();
00055   virtual ~RosImagesThread();
00056 
00057   virtual void init();
00058   virtual void loop();
00059   virtual void finalize();
00060 
00061  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00062  protected: virtual void run() { Thread::run(); }
00063 
00064  private:
00065   void update_images();
00066   void get_sets(std::set<std::string> &missing_images,
00067                 std::set<std::string> &unbacked_images);
00068 
00069  private:
00070   /// @cond INTERNALS
00071   typedef struct {
00072     image_transport::Publisher           pub;
00073     sensor_msgs::Image                   msg;
00074     fawkes::Time                         last_sent;
00075     firevision::SharedMemoryImageBuffer *img;
00076   } PublisherInfo;
00077   /// @endcond
00078   std::map<std::string, PublisherInfo> pubs_;
00079 
00080   image_transport::ImageTransport *it_;
00081   fawkes::Time *last_update_;
00082   fawkes::Time *now_;
00083 
00084 };
00085 
00086 #endif