convert.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Austin Robot Technology, Jack O'Quin
3  * Copyright (C) 2011 Jesse Vera
4  * Copyright (C) 2012 Austin Robot Technology, Jack O'Quin
5  * Copyright (C) 2017 Robosense, Tony Zhang
6  * License: Modified BSD Software License Agreement
7  *
8 
9  Copyright (C) 2010-2013 Austin Robot Technology, and others
10  All rights reserved.
11 
12 
13 Modified BSD License:
14 --------------------
15 
16  Redistribution and use in source and binary forms, with or without
17  modification, are permitted provided that the following conditions
18  are met:
19 
20  * Redistributions of source code must retain the above copyright
21  notice, this list of conditions and the following disclaimer.
22 
23  * Redistributions in binary form must reproduce the above
24  copyright notice, this list of conditions and the following
25  disclaimer in the documentation and/or other materials provided
26  with the distribution.
27 
28  * Neither the names of the University of Texas at Austin, nor
29  Austin Robot Technology, nor the names of other contributors may
30  be used to endorse or promote products derived from this
31  software without specific prior written permission.
32 
33  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 POSSIBILITY OF SUCH DAMAGE.
45  */
46 
52 #include "convert.h"
54 
55 namespace rslidar_pointcloud
56 {
57 std::string model;
58 
60 Convert::Convert(ros::NodeHandle node, ros::NodeHandle private_nh) : data_(new rslidar_rawdata::RawData())
61 {
62  data_->loadConfigFile(node, private_nh); // load lidar parameters
63  private_nh.param("model", model, std::string("RS16"));
64 
65  // advertise output point cloud (before subscribing to input data)
66  output_ = node.advertise<sensor_msgs::PointCloud2>("rslidar_points", 10);
67 
68  srv_ = boost::make_shared<dynamic_reconfigure::Server<rslidar_pointcloud::CloudNodeConfig> >(private_nh);
69  dynamic_reconfigure::Server<rslidar_pointcloud::CloudNodeConfig>::CallbackType f;
70  f = boost::bind(&Convert::callback, this, _1, _2);
71  srv_->setCallback(f);
72 
73  // subscribe to rslidarScan packets
74  rslidar_scan_ = node.subscribe("rslidar_packets", 10, &Convert::processScan, (Convert*)this,
75  ros::TransportHints().tcpNoDelay(true));
76 }
77 
78 void Convert::callback(rslidar_pointcloud::CloudNodeConfig& config, uint32_t level)
79 {
80  ROS_INFO("Reconfigure Request");
81  // config_.time_offset = config.time_offset;
82 }
83 
85 void Convert::processScan(const rslidar_msgs::rslidarScan::ConstPtr& scanMsg)
86 {
87  pcl::PointCloud<pcl::PointXYZI>::Ptr outPoints(new pcl::PointCloud<pcl::PointXYZI>);
88  outPoints->header.stamp = pcl_conversions::toPCL(scanMsg->header).stamp;
89  outPoints->header.frame_id = scanMsg->header.frame_id;
90  outPoints->clear();
91  if (model == "RS16")
92  {
93  outPoints->height = 16;
94  outPoints->width = 24 * (int)scanMsg->packets.size();
95  outPoints->is_dense = false;
96  outPoints->resize(outPoints->height * outPoints->width);
97  }
98  else if (model == "RS32")
99  {
100  outPoints->height = 32;
101  outPoints->width = 12 * (int)scanMsg->packets.size();
102  outPoints->is_dense = false;
103  outPoints->resize(outPoints->height * outPoints->width);
104  }
105 
106  // process each packet provided by the driver
107 
108  data_->block_num = 0;
109  for (size_t i = 0; i < scanMsg->packets.size(); ++i)
110  {
111  data_->unpack(scanMsg->packets[i], outPoints);
112  }
113  sensor_msgs::PointCloud2 outMsg;
114  pcl::toROSMsg(*outPoints, outMsg);
115 
116  output_.publish(outMsg);
117 }
118 } // namespace rslidar_pointcloud
void processScan(const rslidar_msgs::rslidarScan::ConstPtr &scanMsg)
Callback for raw scan messages.
Definition: convert.cc:85
void publish(const boost::shared_ptr< M > &message) const
f
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string model
Definition: convert.cc:57
void callback(rslidar_pointcloud::CloudNodeConfig &config, uint32_t level)
Definition: convert.cc:78
ros::Subscriber rslidar_scan_
Definition: convert.h:81
boost::shared_ptr< dynamic_reconfigure::Server< rslidar_pointcloud::CloudNodeConfig > > srv_
Pointer to dynamic reconfigure service srv_.
Definition: convert.h:78
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Convert(ros::NodeHandle node, ros::NodeHandle private_nh)
Constructor.
Definition: convert.cc:60
boost::shared_ptr< rslidar_rawdata::RawData > data_
Definition: convert.h:80
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
ros::Publisher output_
Definition: convert.h:82
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)


rslidar_pointcloud
Author(s): Tony Zhang , Tony Zhang, George Wang, Piyush Khandelwal, Jesse Vera
autogenerated on Mon Jun 10 2019 14:41:10