depth_and_info_subscriber.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2011, Nico Blodow <blodow@cs.tum.edu>
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 the Intelligent Autonomous Systems Group/
00014  *       Technische Universitaet Muenchen nor the names of its contributors 
00015  *       may be used to endorse or promote products derived from this software 
00016  *       without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 
00032 #ifndef REALTIME_URDF_FILTER_DEPTH_AND_INFO_SUBSCRIBER_H_
00033 #define REALTIME_URDF_FILTER_DEPTH_AND_INFO_SUBSCRIBER_H_
00034 
00035 #include <ros/ros.h>
00036 
00037 #include <message_filters/subscriber.h>
00038 #include <message_filters/synchronizer.h>
00039 #include <message_filters/sync_policies/approximate_time.h>
00040 
00041 #include <cv_bridge/cv_bridge.h>
00042 
00043 #include <sensor_msgs/Image.h>
00044 #include <sensor_msgs/CameraInfo.h>
00045 #include <sensor_msgs/image_encodings.h>
00046 
00047 #include <boost/function.hpp>
00048 
00049 namespace realtime_urdf_filter
00050 {
00051   typedef message_filters::sync_policies::ApproximateTime <sensor_msgs::Image, sensor_msgs::CameraInfo > DepthAndInfoSyncPolicy;
00052 
00053   class DepthAndInfoSubscriber
00054   {
00055   public:
00056     typedef boost::function<void (const sensor_msgs::ImageConstPtr& depth_image,
00057                                   const sensor_msgs::CameraInfo::ConstPtr& camera_matrix) > Callback;
00058 
00059     message_filters::Subscriber<sensor_msgs::Image> depth_img_sub;
00060     message_filters::Subscriber<sensor_msgs::CameraInfo> cam_info_sub;
00061 
00062     message_filters::Synchronizer<DepthAndInfoSyncPolicy> di_sync;
00063 
00064     Callback callback;
00065 
00066     DepthAndInfoSubscriber (ros::NodeHandle comm_nh, Callback cb) 
00067       : depth_img_sub (comm_nh, "/camera/depth_registered/image", 10)
00068       , cam_info_sub (comm_nh, "/camera/rgb/camera_info", 10)
00069       , di_sync (DepthAndInfoSyncPolicy(100), depth_img_sub, cam_info_sub )
00070       , callback (cb)
00071     {
00072       di_sync.registerCallback (boost::bind (&DepthAndInfoSubscriber::depthAndInfoCb, this, _1,_2));
00073 
00074       ROS_INFO ("Subscribed to depth image on: %s", depth_img_sub.getTopic().c_str ());
00075       ROS_INFO ("Subscribed to camera info on: %s", cam_info_sub.getTopic().c_str ());
00076     }
00077 
00078     void depthAndInfoCb (const sensor_msgs::Image::ConstPtr& depth_img_msg,
00079                          const sensor_msgs::CameraInfo::ConstPtr& camera_info_msg)
00080     {
00081       callback (depth_img_msg, camera_info_msg);
00082     }
00083   };
00084 
00085 
00086 
00087 }
00088 
00089 #endif // REALTIME_URDF_FILTER_DEPTH_AND_INFO_SUBSCRIBER_H_


realtime_urdf_filter
Author(s): Nico Blodow
autogenerated on Mon Oct 6 2014 04:04:44