scan_mask_filter.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2017, laser_filters authors
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_FILTERS_SCAN_MASK_FILTER_H
36 #define LASER_FILTERS_SCAN_MASK_FILTER_H
37 
43 #include "filters/filter_base.h"
44 #include "sensor_msgs/LaserScan.h"
45 
46 #include <XmlRpcException.h>
47 
48 #include <limits>
49 #include <map>
50 #include <string>
51 #include <vector>
52 
53 namespace laser_filters
54 {
55 
56 class LaserScanMaskFilter : public filters::FilterBase<sensor_msgs::LaserScan>
57 {
58 public:
59  std::map<std::string, std::vector<size_t> > masks_;
60 
61  bool configure()
62  {
63  XmlRpc::XmlRpcValue config;
64  if (!getParam("masks", config))
65  {
66  ROS_ERROR("LaserScanMaskFilter: masks is not defined in the config.");
67  return false;
68  }
70  {
71  ROS_ERROR("LaserScanMaskFilter: masks must be an array of frame_ids with direction list.");
72  return false;
73  }
74  for (XmlRpc::XmlRpcValue::iterator it = config.begin();
75  it != config.end(); ++it)
76  {
77  if (it->second.getType() == XmlRpc::XmlRpcValue::TypeArray)
78  {
79  std::string frame_id = (std::string)(it->first);
80  masks_[frame_id] = std::vector<size_t>();
81  try
82  {
83  for (size_t i = 0; i < it->second.size(); ++i)
84  {
85  size_t id = static_cast<int>(it->second[i]);
86  masks_[frame_id].push_back(id);
87  }
88  ROS_INFO("LaserScanMaskFilter: %s: %d directions will be masked.",
89  frame_id.c_str(), (int)masks_[frame_id].size());
90  }
91  catch(XmlRpc::XmlRpcException &e)
92  {
93  ROS_ERROR("LaserScanMaskFilter: %s", e.getMessage().c_str());
94  return false;
95  }
96  }
97  }
98  return true;
99  }
100 
102  {
103  }
104 
105  bool update(const sensor_msgs::LaserScan& data_in, sensor_msgs::LaserScan& data_out)
106  {
107  data_out = data_in;
108  if (masks_.find(data_out.header.frame_id) == masks_.end())
109  {
110  ROS_WARN("LaserScanMaskFilter: frame_id %s is not registered.",
111  data_out.header.frame_id.c_str());
112  return true;
113  }
114 
115  const std::vector<size_t> &mask = masks_[data_out.header.frame_id];
116  const size_t len = data_out.ranges.size();
117  for (std::vector<size_t>::const_iterator it = mask.begin();
118  it != mask.end(); ++it)
119  {
120  if (*it > len) continue;
121  data_out.ranges[*it] = std::numeric_limits<float>::quiet_NaN();
122  }
123 
124  return true;
125  }
126 };
127 
128 } // namespace laser_filters
129 
130 #endif // LASER_FILTERS_SCAN_MASK_FILTER_H
const std::string & getMessage() const
std::map< std::string, std::vector< size_t > > masks_
ValueStruct::iterator iterator
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
Type const & getType() const
#define ROS_WARN(...)
bool getParam(const std::string &name, std::string &value)
bool update(const sensor_msgs::LaserScan &data_in, sensor_msgs::LaserScan &data_out)
#define ROS_INFO(...)
#define ROS_ERROR(...)


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