intensity_filter.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * Copyright (c) 2020, Eurotec B.V.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the Willow Garage nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * \author Vijay Pradeep, Rein Appeldoorn
36 *
37 *********************************************************************/
38 
40 #include <ros/node_handle.h>
41 
42 namespace laser_filters
43 {
45 {
46 }
47 
49 {
50  ros::NodeHandle private_nh("~" + getName());
51  dyn_server_.reset(new dynamic_reconfigure::Server<IntensityFilterConfig>(own_mutex_, private_nh));
52  dynamic_reconfigure::Server<IntensityFilterConfig>::CallbackType f;
53  f = boost::bind(&LaserScanIntensityFilter::reconfigureCB, this, _1, _2);
54  dyn_server_->setCallback(f);
55 
56  getParam("lower_threshold", config_.lower_threshold);
57  getParam("upper_threshold", config_.upper_threshold);
58  getParam("invert", config_.invert);
59 
60  getParam("filter_override_range", config_.filter_override_range);
61  getParam("filter_override_intensity", config_.filter_override_intensity);
62  dyn_server_->updateConfig(config_);
63  return true;
64 }
65 
66 bool LaserScanIntensityFilter::update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
67 {
68  filtered_scan = input_scan;
69 
70  // Need to check ever reading in the current scan
71  for (unsigned int i=0; i < input_scan.ranges.size() && i < input_scan.intensities.size(); i++)
72  {
73  float& range = filtered_scan.ranges[i];
74  float& intensity = filtered_scan.intensities[i];
75 
76  // Is this reading below our lower threshold?
77  // Is this reading above our upper threshold?
78  bool filter = intensity <= config_.lower_threshold || intensity >= config_.upper_threshold;
79  if (config_.invert)
80  {
81  filter = !filter;
82  }
83 
84  if (filter)
85  {
86  if (config_.filter_override_range)
87  {
88  // If so, then make it an invalid value (NaN)
89  range = std::numeric_limits<float>::quiet_NaN();
90  }
91  if (config_.filter_override_intensity)
92  {
93  intensity = 0.0; // Not intense
94  }
95  }
96  else
97  {
98  if (config_.filter_override_intensity)
99  {
100  intensity = 1.0; // Intense
101  }
102  }
103  }
104 
105  return true;
106 }
107 
108 void LaserScanIntensityFilter::reconfigureCB(IntensityFilterConfig& config, uint32_t level)
109 {
110  config_ = config;
111 }
112 }
f
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
bool getParam(const std::string &name, std::string &value) const
void reconfigureCB(IntensityFilterConfig &config, uint32_t level)
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &output_scan)
std::shared_ptr< dynamic_reconfigure::Server< IntensityFilterConfig > > dyn_server_


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