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 "filters/filter_base.h"
44 #include "sensor_msgs/LaserScan.h"
45 
46 namespace laser_filters
47 {
48 
49 class LaserScanRangeFilter : public filters::FilterBase<sensor_msgs::LaserScan>
50 {
51 public:
52 
58 
59  bool configure()
60  {
61  use_message_range_limits_ = false;
62  getParam("use_message_range_limits", use_message_range_limits_);
63 
64  // work around the not implemented getParam(std::string name, float& value) method
65  double temp_replacement_value = std::numeric_limits<double>::quiet_NaN();
66  getParam("lower_replacement_value", temp_replacement_value);
67  lower_replacement_value_ = static_cast<float>(temp_replacement_value);
68 
69  // work around the not implemented getParam(std::string name, float& value) method
70  temp_replacement_value = std::numeric_limits<double>::quiet_NaN();
71  getParam("upper_replacement_value", temp_replacement_value);
72  upper_replacement_value_ = static_cast<float>(temp_replacement_value);
73 
74 
75  lower_threshold_ = 0.0;
76  upper_threshold_ = 100000.0;
77  getParam("lower_threshold", lower_threshold_);
78  getParam("upper_threshold", upper_threshold_) ;
79  return true;
80  }
81 
83  {
84 
85  }
86 
87  bool update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
88  {
89  if (use_message_range_limits_)
90  {
91  lower_threshold_ = input_scan.range_min;
92  upper_threshold_ = input_scan.range_max;
93  }
94  filtered_scan = input_scan;
95  for (unsigned int i=0;
96  i < input_scan.ranges.size();
97  i++) // Need to check ever reading in the current scan
98  {
99 
100  if (filtered_scan.ranges[i] <= lower_threshold_)
101  {
102  filtered_scan.ranges[i] = lower_replacement_value_;
103 
104  }
105  else if (filtered_scan.ranges[i] >= upper_threshold_)
106  {
107  filtered_scan.ranges[i] = upper_replacement_value_;
108  }
109  }
110 
111  return true;
112  }
113 } ;
114 
115 }
116 
117 #endif // LASER_SCAN_RANGE_FILTER_H
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
bool getParam(const std::string &name, std::string &value)
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &filtered_scan)
Definition: range_filter.h:87


laser_filters
Author(s): Tully Foote
autogenerated on Tue Mar 17 2020 03:40:02