00001
00002
00003
00004
00005
00006
00007
00015 #include <pluginlib/class_list_macros.h>
00016 #include <nodelet/nodelet.h>
00017 #include <ros/ros.h>
00018 #include <velodyne_common/RawScan.h>
00019 #include <velodyne_msgs/VelodyneScan.h>
00020
00021 class ConvertBack: public nodelet::Nodelet
00022 {
00023 public:
00024 ConvertBack() {}
00025 ~ConvertBack() {}
00026 virtual void onInit();
00027
00028 private:
00029 void processScan(const velodyne_msgs::VelodyneScanPtr &scan);
00030
00031 ros::Subscriber scan_;
00032 ros::Publisher output_;
00033 };
00034
00035 void ConvertBack::onInit()
00036 {
00037 ros::NodeHandle node = getNodeHandle();
00038
00039
00040 scan_ =
00041 node.subscribe("velodyne/packets", 1,
00042 &ConvertBack::processScan, this,
00043 ros::TransportHints().tcpNoDelay(true));
00044
00045 output_ =
00046 node.advertise<velodyne_common::RawScan>("velodyne/rawscan", 10);
00047 }
00048
00053 void ConvertBack::processScan(const velodyne_msgs::VelodyneScanPtr &scan)
00054 {
00055 if (output_.getNumSubscribers() == 0)
00056 return;
00057
00058
00059 velodyne_common::RawScanPtr msg(new velodyne_common::RawScan);
00060
00061
00062 msg->header.stamp = scan->header.stamp ;
00063 msg->header.frame_id = scan->header.frame_id;
00064
00065 size_t npackets = scan->packets.size();
00066 size_t packet_size = velodyne_common::RawScan::PACKET_SIZE;
00067 size_t nbytes = npackets * packet_size;
00068
00069
00070 msg->data.resize(nbytes);
00071 size_t next = 0;
00072 for (size_t pkt = 0; pkt < npackets; ++pkt)
00073 {
00074 for (size_t i = 0; i < packet_size; ++i)
00075 {
00076 msg->data[next++] = scan->packets[pkt].data[i];
00077 }
00078 }
00079
00080
00081 ROS_ASSERT(next == nbytes);
00082 NODELET_DEBUG_STREAM("Publishing " << nbytes << " Velodyne points.");
00083 output_.publish(msg);
00084 }
00085
00086
00087
00088
00089 PLUGINLIB_DECLARE_CLASS(velodyne_common, ConvertBack,
00090 ConvertBack, nodelet::Nodelet);