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