laser_scan_densifier.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /*
17  * Copyright (c) 2011, Ivan Dryanovski, William Morris
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above copyright
26  * notice, this list of conditions and the following disclaimer in the
27  * documentation and/or other materials provided with the distribution.
28  * * Neither the name of the CCNY Robotics Lab nor the names of its
29  * contributors may be used to endorse or promote products derived from
30  * this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
36  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGE.
43  */
44 
46 
47 namespace scan_tools {
48 
50  nh_(nh),
51  nh_private_(nh_private)
52 {
53  ROS_INFO ("Starting LaserScanDensifier");
54 
55  // **** get paramters
56 
57  nh_private_.param("step", step_, 2);
58  nh_private_.param("mode", mode_, 0);
59 
60  if (step_ <= 0)
61  {
62  ROS_ERROR("LaserScanDensifier has step parameter set to %d, must be > 0! Not initiating subscriptions...", step_);
63  exit(-1);
64  }
65 
66  switch(mode_) {
67  case 0: ROS_INFO("LaserScanDensifier started with mode %d: copy data points", mode_);
68  break;
69  case 1: ROS_INFO("LaserScanDensifier started with mode %d: interpolate data points", mode_);
70  break;
71  default: ROS_WARN("LaserScanDensifier started with unsupported mode %d. Defaulting to mode 0: copy data points", mode_);
72  mode_ = 0;
73  break;
74  }
75 
76  // **** advertise topics
77 
78  scan_publisher_ = nh_.advertise<sensor_msgs::LaserScan>("scan_dense", 1);
79 
80  // **** subscribe to laser scan messages
81 
83 }
84 
86 {
87  ROS_INFO ("Destroying LaserScanDensifier");
88 }
89 
90 void LaserScanDensifier::scanCallback (const sensor_msgs::LaserScanConstPtr& scan_msg)
91 {
92  sensor_msgs::LaserScan::Ptr scan_dense;
93  scan_dense = boost::make_shared<sensor_msgs::LaserScan>();
94 
95  // copy over equal fields
96 
97  scan_dense->header = scan_msg->header;
98  scan_dense->range_min = scan_msg->range_min;
99  scan_dense->range_max = scan_msg->range_max;
100  scan_dense->angle_min = scan_msg->angle_min;
101  scan_dense->angle_max = scan_msg->angle_max;
102  scan_dense->angle_increment = scan_msg->angle_increment / step_;
103  scan_dense->time_increment = scan_msg->time_increment;
104  scan_dense->scan_time = scan_msg->scan_time;
105 
106  scan_dense->ranges.clear();
107  scan_dense->intensities.clear();
108 
109  for (size_t i = 0; i < scan_msg->ranges.size()-1; i++)
110  {
111  switch (mode_) {
112  case 0: { //copy data points
113  scan_dense->ranges.insert(scan_dense->ranges.end(), step_, scan_msg->ranges[i]);
114  scan_dense->intensities.insert(scan_dense->intensities.end(), step_, scan_msg->intensities[i]);
115  break;
116  }
117  case 1: { //interpolate data points
118  double delta_range = (scan_msg->ranges[i+1]-scan_msg->ranges[i])/step_;
119  double delta_intensities = (scan_msg->intensities[i+1]-scan_msg->intensities[i])/step_;
120  for (int k = 0; k < step_; k++) {
121  scan_dense->ranges.insert(scan_dense->ranges.end(), 1, scan_msg->ranges[i]+k*delta_range);
122  scan_dense->intensities.insert(scan_dense->intensities.end(), 1, scan_msg->intensities[i]+k*delta_intensities);
123  }
124  break;
125  }
126  }
127  }
128  // add angle_max data point
129  scan_dense->ranges.push_back(scan_msg->ranges.back());
130  scan_dense->intensities.push_back(scan_msg->intensities.back());
131 
132  scan_publisher_.publish(scan_dense);
133 }
134 
135 } //namespace scan_tools
136 
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
LaserScanDensifier(ros::NodeHandle nh, ros::NodeHandle nh_private)
#define ROS_WARN(...)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void scanCallback(const sensor_msgs::LaserScanConstPtr &scan_msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_ERROR(...)


laser_scan_densifier
Author(s): Felix Messmer
autogenerated on Wed Apr 7 2021 02:12:00