Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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_