interpolation_filter.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
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 INTERPOLATION_FILTER_H
36 #define INTERPOLATION_FILTER_H
37 
44 #include "filters/filter_base.h"
45 #include "sensor_msgs/LaserScan.h"
46 
47 namespace laser_filters
48 {
49 
50 class InterpolationFilter : public filters::FilterBase<sensor_msgs::LaserScan>
51 {
52 public:
53 
54  bool configure()
55  {
56  return true;
57  }
58 
60  {
61  }
62 
63  bool update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
64  {
65  double previous_valid_range = input_scan.range_max - .01;
66  double next_valid_range = input_scan.range_max - .01;
67  filtered_scan= input_scan;
68 
69  unsigned int i = 0;
70  while(i < input_scan.ranges.size()) // Need to check every reading in the current scan
71  {
72  //check if the reading is out of range for some reason
73  if (filtered_scan.ranges[i] <= input_scan.range_min ||
74  filtered_scan.ranges[i] >= input_scan.range_max){
75 
76  //we need to find the next valid range reading
77  unsigned int j = i + 1;
78  unsigned int start_index = i;
79  unsigned int end_index = i;
80  while(j < input_scan.ranges.size()){
81  if (filtered_scan.ranges[j] <= input_scan.range_min ||
82  filtered_scan.ranges[j] >= input_scan.range_max){
83  end_index = j;
84  }
85  else{
86  next_valid_range = filtered_scan.ranges[j];
87  break;
88  }
89  ++j;
90  }
91 
92  //for now, we'll just take the average between the two valid range readings
93  double average_range = (previous_valid_range + next_valid_range) / 2.0;
94 
95  for(unsigned int k = start_index; k <= end_index; k++){
96  filtered_scan.ranges[k] = average_range;
97  }
98 
99  //make sure to update our previous valid range reading
100  previous_valid_range = next_valid_range;
101  i = j + 1;
102  }
103  else{
104  previous_valid_range = filtered_scan.ranges[i];
105  ++i;
106  }
107 
108  }
109  return true;
110  }
111 };
112 
113 }
114 
115 #endif // LASER_SCAN_INTENSITY_FILTER_H
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &filtered_scan)


laser_filters
Author(s): Tully Foote
autogenerated on Wed Jul 3 2019 19:33:47