sector_filter.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * BSD 2-Clause License
3 *
4 * Copyright (c) 2021, Jimmy F. Klarke
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * \author: Jimmy F. Klarke
30 *********************************************************************/
31 
32 #include <math.h>
33 
35 #include <ros/node_handle.h>
36 
37 namespace laser_filters
38 {
39 
41 {
42 }
43 
45 {
46  ros::NodeHandle private_nh("~" + getName());
47  dyn_server_.reset(new dynamic_reconfigure::Server<SectorFilterConfig>(own_mutex_, private_nh));
48  dynamic_reconfigure::Server<SectorFilterConfig>::CallbackType f;
49  f = boost::bind(&LaserScanSectorFilter::reconfigureCB, this, _1, _2);
50  dyn_server_->setCallback(f);
51 
52  getParam("angle_min", config_.angle_min);
53  getParam("angle_max", config_.angle_max);
54  getParam("range_min", config_.range_min);
55  getParam("range_max", config_.range_max);
56  getParam("clear_inside", config_.clear_inside);
57  getParam("invert", config_.invert);
58 
59  ROS_INFO("clear_inside(!invert): %s", (isClearInside() ? "true" : "false"));
60 
61  dyn_server_->updateConfig(config_);
62  return true;
63 }
64 
65 void LaserScanSectorFilter::reconfigureCB(SectorFilterConfig& config, uint32_t level)
66 {
67  config_ = config;
68 }
69 
71 {
72  bool clear_inside = config_.clear_inside;
73  bool invert = config_.invert;
74 
75  clear_inside = invert ? false : clear_inside;
76 
77  return clear_inside;
78 }
79 
80 bool LaserScanSectorFilter::update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
81 {
82  filtered_scan = input_scan; //copy entire message
83 
84  double angle_min = config_.angle_min;
85  double angle_max = config_.angle_max;
86  double range_min = config_.range_min;
87  double range_max = config_.range_max;
88  bool clear_inside = isClearInside();
89 
90  double angle_delta = angle_max - angle_min;
91  if (angle_max < angle_min)
92  {
93  angle_delta += M_PI * 2;
94  }
95 
96  double current_angle = input_scan.angle_min;
97  unsigned int count = 0;
98  //loop through the scan and remove ranges at angles between lower_angle_ and upper_angle_
99  for (size_t i = 0; i < input_scan.ranges.size(); ++i)
100  {
101  current_angle = (i == 0) ? current_angle : (current_angle + input_scan.angle_increment);
102 
103  double current_range = input_scan.ranges[i];
104  double current_angle_delta = current_angle - angle_min;
105  if ((angle_max < angle_min) && (current_angle_delta < 0))
106  {
107  current_angle_delta += M_PI * 2;
108  }
109 
110  if (clear_inside != ((current_angle_delta > 0)
111  && (current_angle_delta < angle_delta)
112  && (current_range > range_min)
113  && (current_range < range_max)))
114  {
115  continue;
116  }
117 
118  filtered_scan.ranges[i] = input_scan.range_max + 1.0;
119  if (i < filtered_scan.intensities.size())
120  {
121  filtered_scan.intensities[i] = 0.0;
122  }
123  count++;
124  }
125 
126  ROS_DEBUG("Filtered out %u points from the laser scan.", count);
127 
128  return true;
129 }
130 
131 } // end namespace laser_filters
f
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
boost::recursive_mutex own_mutex_
Definition: sector_filter.h:57
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &output_scan)
#define ROS_INFO(...)
bool getParam(const std::string &name, std::string &value) const
std::shared_ptr< dynamic_reconfigure::Server< SectorFilterConfig > > dyn_server_
Definition: sector_filter.h:55
void reconfigureCB(SectorFilterConfig &config, uint32_t level)
#define ROS_DEBUG(...)


laser_filters
Author(s): Tully Foote
autogenerated on Mon Feb 28 2022 22:39:24