convert.cc
Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2009, 2010 Austin Robot Technology, Jack O'Quin
00003  *  Copyright (C) 2011 Jesse Vera
00004  *  Copyright (C) 2012 Austin Robot Technology, Jack O'Quin
00005  *  License: Modified BSD Software License Agreement
00006  *
00007  *  $Id$
00008  */
00009 
00016 #include "convert.h"
00017 
00018 #include <pcl_conversions/pcl_conversions.h>
00019 
00020 namespace velodyne_pointcloud
00021 {
00023   Convert::Convert(ros::NodeHandle node, ros::NodeHandle private_nh):
00024     data_(new velodyne_rawdata::RawData())
00025   {
00026     data_->setup(private_nh);
00027 
00028 
00029     // advertise output point cloud (before subscribing to input data)
00030     output_ =
00031       node.advertise<sensor_msgs::PointCloud2>("velodyne_points", 10);
00032       
00033     srv_ = boost::make_shared <dynamic_reconfigure::Server<velodyne_pointcloud::
00034       VelodyneConfigConfig> > (private_nh);
00035     dynamic_reconfigure::Server<velodyne_pointcloud::VelodyneConfigConfig>::
00036       CallbackType f;
00037     f = boost::bind (&Convert::callback, this, _1, _2);
00038     srv_->setCallback (f);
00039 
00040     // subscribe to VelodyneScan packets
00041     velodyne_scan_ =
00042       node.subscribe("velodyne_packets", 10,
00043                      &Convert::processScan, (Convert *) this,
00044                      ros::TransportHints().tcpNoDelay(true));
00045   }
00046   
00047   void Convert::callback(velodyne_pointcloud::VelodyneConfigConfig &config,
00048                 uint32_t level)
00049   {
00050   ROS_INFO("Reconfigure Request");
00051   data_->setParameters(config.min_range, config.max_range, config.view_direction,
00052                        config.view_width);
00053   }
00054 
00056   void Convert::processScan(const velodyne_msgs::VelodyneScan::ConstPtr &scanMsg)
00057   {
00058     if (output_.getNumSubscribers() == 0)         // no one listening?
00059       return;                                     // avoid much work
00060 
00061     // allocate a point cloud with same time and frame ID as raw data
00062     velodyne_rawdata::VPointCloud::Ptr
00063       outMsg(new velodyne_rawdata::VPointCloud());
00064     // outMsg's header is a pcl::PCLHeader, convert it before stamp assignment
00065     outMsg->header.stamp = pcl_conversions::toPCL(scanMsg->header).stamp;
00066     outMsg->header.frame_id = scanMsg->header.frame_id;
00067     outMsg->height = 1;
00068 
00069     // process each packet provided by the driver
00070     for (size_t i = 0; i < scanMsg->packets.size(); ++i)
00071       {
00072         data_->unpack(scanMsg->packets[i], *outMsg);
00073       }
00074 
00075     // publish the accumulated cloud message
00076     ROS_DEBUG_STREAM("Publishing " << outMsg->height * outMsg->width
00077                      << " Velodyne points, time: " << outMsg->header.stamp);
00078     output_.publish(outMsg);
00079   }
00080 
00081 } // namespace velodyne_pointcloud


velodyne_pointcloud
Author(s): Jack O'Quin, Piyush Khandelwal, Jesse Vera
autogenerated on Thu Aug 27 2015 15:37:05