Go to the documentation of this file.00001
00060 #include "cob_people_detection/sensor_message_gateway_node.h"
00061 #include "cob_vision_utils/GlobalDefines.h"
00062
00063
00064 #include <pcl/point_types.h>
00065 #include <pcl_ros/point_cloud.h>
00066
00067
00068 #include <boost/bind.hpp>
00069
00070 namespace cob_people_detection
00071 {
00072 SensorMessageGatewayNode::SensorMessageGatewayNode(ros::NodeHandle nh) :
00073 node_handle_(nh)
00074 {
00075 ros::Duration(5.0).sleep();
00076
00077 it_ = 0;
00078
00079 last_publishing_time_pcl_ = ros::Time::now();
00080 last_publishing_time_image_ = ros::Time::now();
00081
00082
00083 std::cout << "\n--------------------------\nSensor Message Gateway Parameters:\n--------------------------\n";
00084 node_handle_.param("target_publishing_rate", target_publishing_rate_, 100.0);
00085 std::cout << "target_publishing_rate = " << target_publishing_rate_ << std::endl;
00086 target_publishing_delay_ = ros::Duration(1.0 / target_publishing_rate_);
00087 node_handle_.param("display_timing", display_timing_, false);
00088 std::cout << "display_timing = " << display_timing_ << std::endl;
00089
00090
00091
00092
00093 reconfigure_server_.setCallback(boost::bind(&SensorMessageGatewayNode::reconfigureCallback, this, _1, _2));
00094
00095 it_ = new image_transport::ImageTransport(node_handle_);
00096
00097
00098 pointcloud_pub_ = node_handle_.advertise<sensor_msgs::PointCloud2>("pointcloud_rgb_out", 1);
00099 color_image_pub_ = it_->advertise("colorimage_out", 1);
00100
00101
00102 pointcloud_sub_ = node_handle_.subscribe("pointcloud_rgb_in", 1, &SensorMessageGatewayNode::pointcloudCallback, this);
00103 color_image_sub_.subscribe(*it_, "colorimage_in", 1);
00104 color_image_sub_.registerCallback(boost::bind(&SensorMessageGatewayNode::imageCallback, this, _1));
00105
00106 std::cout << "SensorMessageGatewayNode initialized." << std::endl;
00107 }
00108
00109 SensorMessageGatewayNode::~SensorMessageGatewayNode(void)
00110 {
00111 if (it_ != 0)
00112 delete it_;
00113 }
00114
00115 void SensorMessageGatewayNode::pointcloudCallback(const sensor_msgs::PointCloud2::ConstPtr& pointcloud)
00116 {
00117
00118
00119
00120
00121
00122
00123
00124 if (target_publishing_rate_ != 0.0 && (ros::Time::now() - last_publishing_time_pcl_) > target_publishing_delay_)
00125 {
00126 pointcloud_pub_.publish(*pointcloud);
00127
00128 if (display_timing_ == true)
00129 ROS_INFO("%d MessageGateway: Time stamp of pointcloud message: %f. Delay: %f.", pointcloud->header.seq, pointcloud->header.stamp.toSec(), ros::Time::now().toSec()-pointcloud->header.stamp.toSec());
00130
00131 last_publishing_time_pcl_ = ros::Time::now();
00132 }
00133 }
00134
00135 void SensorMessageGatewayNode::imageCallback(const sensor_msgs::ImageConstPtr& color_image_msg)
00136 {
00137
00138
00139
00140
00141
00142
00143
00144 if (target_publishing_rate_ != 0.0 && (ros::Time::now() - last_publishing_time_image_) > target_publishing_delay_)
00145 {
00146 color_image_pub_.publish(*color_image_msg);
00147
00148 last_publishing_time_image_ = ros::Time::now();
00149 }
00150 }
00151
00152 void SensorMessageGatewayNode::reconfigureCallback(cob_people_detection::sensor_message_gatewayConfig &config, uint32_t level)
00153 {
00154 target_publishing_rate_ = config.target_publishing_rate;
00155 target_publishing_delay_ = ros::Duration(1.0 / target_publishing_rate_);
00156 ROS_INFO("Reconfigure request accomplished. New target publishing rate: %f", config.target_publishing_rate);
00157 }
00158 }