ImageSubscription.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2010, Ulrich Klank, Dejan Pangercic
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "Sensor.h"
00031 #include "XMLTag.h"
00032 
00033 #include <ros/ros.h>
00034 #include <ros/node_handle.h>
00035 #include <sensor_msgs/Image.h>
00036 #include "IplImageReading.h"
00037 
00038 #define XML_NODE_IMAGESUBSCRIPTION "ImageSubscription"
00039 #define XML_PROPERTY_TOPIC "TopicName"
00040 #define XML_ATTRIBUTE_FOCAL_LENGTH "focal_length"
00041 #define XML_ATTRIBUTE_PIX_SIZE_X "pix_size_x"
00042 #define XML_ATTRIBUTE_PIX_SIZE_Y "pix_size_y"
00043 #define XML_ATTRIBUTE_PROJ_CENTER_X "proj_center_x"
00044 #define XML_ATTRIBUTE_PROJ_CENTER_Y "proj_center_y"
00045 
00046 namespace sensor_msgs
00047 {
00048    class CvBridge;
00049 }
00050 
00051 namespace cop
00052 {
00053 
00054   class ImageSubscription : public Sensor
00055   {
00056   public:
00057     ImageSubscription() :
00058           m_bWindowCreated(false),
00059           m_grabbing(false)
00060     {
00061 
00062     }
00063 
00064     ~ImageSubscription(){Stop();}
00065     std::string GetWindowName();
00069     std::string GetName() const{return XML_NODE_IMAGESUBSCRIPTION;};
00075     void Show(const long frame);
00081     Reading*    GetReading(const long &Frame);
00082 
00088     bool        CanSee(RelPose &pose) const;
00089 
00090     void CallBack(const sensor_msgs::ImageConstPtr& msg_ptr);
00091 
00096     bool        Start()
00097     {
00098       printf("Start subscribing topic %s \n", m_stTopicName.c_str());
00099       ros::NodeHandle nh;
00100       printf("Subscribe to topic %s \n", m_stTopicName.c_str());
00101       m_imageSub = nh.subscribe (m_stTopicName, 1, &ImageSubscription::CallBack, this);
00102       m_grabbing = true;
00103       return true;
00104     }
00109     bool        Stop()
00110     {
00111       m_grabbing = false;
00112       m_imageSub.shutdown();
00113       return true;
00114       /*TODO unsunscribe*/
00115     }
00119     /*RelPose* GetRelPose(){return m_relPose;}*/
00120 
00121     XMLTag* Save()
00122     {
00123       XMLTag* tag = new XMLTag(GetName());
00124       Sensor::SaveTo(tag);
00125       tag->AddProperty(XML_PROPERTY_TOPIC, m_stTopicName);
00126       tag->AddProperty(XML_ATTRIBUTE_FOCAL_LENGTH, m_calib.focal_length);
00127       tag->AddProperty(XML_ATTRIBUTE_PIX_SIZE_X, m_calib.pix_size_x);
00128       tag->AddProperty(XML_ATTRIBUTE_PIX_SIZE_Y, m_calib.pix_size_y);
00129       tag->AddProperty(XML_ATTRIBUTE_PROJ_CENTER_X, m_calib.proj_center_x);
00130       tag->AddProperty(XML_ATTRIBUTE_PROJ_CENTER_Y, m_calib.proj_center_y);
00131       return tag;
00132     }
00136     bool IsCamera() const {return true;}
00140     MinimalCalibration m_calib;
00141     std::pair< std::string, std::vector<double> > GetUnformatedCalibrationValues()
00142     {
00143       std::vector<double> vec; 
00144       vec.push_back(m_calib.focal_length); 
00145       vec.push_back(m_calib.pix_size_x); 
00146       vec.push_back(m_calib.pix_size_y); 
00147       vec.push_back(m_calib.proj_center_x); 
00148       vec.push_back(m_calib.proj_center_y); 
00149       
00150       return std::pair< std::string, std::vector<double> >("RECTHALCONCALIB", vec);
00151     }
00152   protected:
00156     void SetData(XMLTag* tag);
00157 
00158   private:
00159       std::string m_stTopicName;
00160       sensor_msgs::CvBridge *m_bridge;
00161       unsigned int m_max_cameraImagesStored;
00162       ros::Subscriber m_imageSub;
00163       bool m_bWindowCreated;
00164       bool m_grabbing;
00165   };
00166 }


cop_ros_plugins
Author(s): U. Klank, Dejan Pangercic
autogenerated on Mon Oct 6 2014 10:51:04