sensor_message_gateway_node.cpp
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 // point cloud
00064 #include <pcl/point_types.h>
00065 #include <pcl_ros/point_cloud.h>
00066 
00067 // boost
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         // Parameters
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         // reconfigure server
00091         //      dynamic_reconfigure::Server<cob_people_detection::sensorMessageGatewayConfig>::CallbackType f;
00092         //      f = boost::bind(&SensorMessageGatewayNode::pointcloudCallback, this, _1, _2);
00093         reconfigure_server_.setCallback(boost::bind(&SensorMessageGatewayNode::reconfigureCallback, this, _1, _2));
00094 
00095         it_ = new image_transport::ImageTransport(node_handle_);
00096 
00097         // advertise topics
00098         pointcloud_pub_ = node_handle_.advertise<sensor_msgs::PointCloud2>("pointcloud_rgb_out", 1);
00099         color_image_pub_ = it_->advertise("colorimage_out", 1);
00100 
00101         // subscribe to sensor topic
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         //      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());
00118 
00119         //      // secure this access with a mutex
00120         //      boost::lock_guard<boost::mutex> lock(image_buffer_mutex_);
00121 
00122         // forward incoming message with desired rate
00123         //std::cout << "Time delay: " << time_delay.toSec() << std::endl;
00124         if (target_publishing_rate_ != 0.0 && (ros::Time::now() - last_publishing_time_pcl_) > target_publishing_delay_)
00125         {
00126                 pointcloud_pub_.publish(*pointcloud);
00127                 //color_image_pub_.publish(image_buffer_);
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                 //std::cout << "published: " << (ros::Time::now()-last_publishing_time_).toSec() << std::endl;
00131                 last_publishing_time_pcl_ = ros::Time::now();
00132         }
00133 }
00134 
00135 void SensorMessageGatewayNode::imageCallback(const sensor_msgs::ImageConstPtr& color_image_msg)
00136 {
00137         //      // secure this access with a mutex
00138         //      boost::lock_guard<boost::mutex> lock(image_buffer_mutex_);
00139 
00140         // store image message
00141         //image_buffer_ = *color_image_msg;
00142 
00143         // forward incoming message with desired rate
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                 //ROS_INFO("%d MessageGateway: Time stamp of image message: %f. Delay: %f.", color_image_msg->header.seq, color_image_msg->header.stamp.toSec(), ros::Time::now().toSec()-color_image_msg->header.stamp.toSec());
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 }


cob_people_detection
Author(s): Richard Bormann , Thomas Zwölfer
autogenerated on Fri Aug 28 2015 10:24:13