range_filter.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, JSK (The University of Tokyo).
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
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #ifndef LASER_SCAN_RANGE_FILTER_H
36 #define LASER_SCAN_RANGE_FILTER_H
37 
43 #include <dynamic_reconfigure/server.h>
44 #include <laser_filters/RangeFilterConfig.h>
45 #include "filters/filter_base.h"
46 #include "sensor_msgs/LaserScan.h"
47 
48 namespace laser_filters
49 {
50 
51 class LaserScanRangeFilter : public filters::FilterBase<sensor_msgs::LaserScan>
52 {
53  std::shared_ptr<dynamic_reconfigure::Server<RangeFilterConfig>> dyn_server_;
54  boost::recursive_mutex own_mutex_;
55 
56  RangeFilterConfig config_ = RangeFilterConfig::__getDefault__();
57 
58 public:
59  bool configure()
60  {
61  ros::NodeHandle private_nh("~" + getName());
62  dyn_server_.reset(new dynamic_reconfigure::Server<RangeFilterConfig>(own_mutex_, private_nh));
63  dynamic_reconfigure::Server<RangeFilterConfig>::CallbackType f;
64  f = boost::bind(&LaserScanRangeFilter::reconfigureCB, this, _1, _2);
65  dyn_server_->setCallback(f);
66 
67  getParam("lower_threshold", config_.lower_threshold);
68  getParam("upper_threshold", config_.upper_threshold);
69  getParam("use_message_range_limits", config_.use_message_range_limits);
70  getParam("lower_replacement_value", config_.lower_replacement_value);
71  getParam("upper_replacement_value", config_.upper_replacement_value);
72 
73  dyn_server_->updateConfig(config_);
74  return true;
75  }
76 
78  {
79 
80  }
81 
82  bool update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
83  {
84  double lower_threshold = config_.lower_threshold;
85  double upper_threshold = config_.upper_threshold;
86 
87  if (config_.use_message_range_limits)
88  {
89  lower_threshold = input_scan.range_min;
90  upper_threshold = input_scan.range_max;
91  }
92  filtered_scan = input_scan;
93  for (unsigned int i=0;
94  i < input_scan.ranges.size();
95  i++) // Need to check ever reading in the current scan
96  {
97 
98  if (filtered_scan.ranges[i] <= lower_threshold)
99  {
100  filtered_scan.ranges[i] = config_.lower_replacement_value;
101 
102  }
103  else if (filtered_scan.ranges[i] >= upper_threshold)
104  {
105  filtered_scan.ranges[i] = config_.upper_replacement_value;
106  }
107  }
108 
109  return true;
110  }
111 
112  void reconfigureCB(RangeFilterConfig& config, uint32_t level)
113  {
114  config_ = config;
115  }
116 } ;
117 
118 }
119 
120 #endif // LASER_SCAN_RANGE_FILTER_H
boost::recursive_mutex own_mutex_
Definition: range_filter.h:54
f
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
std::shared_ptr< dynamic_reconfigure::Server< RangeFilterConfig > > dyn_server_
Definition: range_filter.h:53
void reconfigureCB(RangeFilterConfig &config, uint32_t level)
Definition: range_filter.h:112
bool getParam(const std::string &name, std::string &value) const
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &filtered_scan)
Definition: range_filter.h:82


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