Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef LASER_FILTERS_SCAN_MASK_FILTER_H
00036 #define LASER_FILTERS_SCAN_MASK_FILTER_H
00037
00043 #include "filters/filter_base.h"
00044 #include "sensor_msgs/LaserScan.h"
00045
00046 #include <XmlRpcException.h>
00047
00048 #include <limits>
00049 #include <map>
00050 #include <string>
00051 #include <vector>
00052
00053 namespace laser_filters
00054 {
00055
00056 class LaserScanMaskFilter : public filters::FilterBase<sensor_msgs::LaserScan>
00057 {
00058 public:
00059 std::map<std::string, std::vector<size_t> > masks_;
00060
00061 bool configure()
00062 {
00063 XmlRpc::XmlRpcValue config;
00064 if (!getParam("masks", config))
00065 {
00066 ROS_ERROR("LaserScanMaskFilter: masks is not defined in the config.");
00067 return false;
00068 }
00069 if (config.getType() == XmlRpc::XmlRpcValue::TypeArray)
00070 {
00071 ROS_ERROR("LaserScanMaskFilter: masks must be an array of frame_ids with direction list.");
00072 return false;
00073 }
00074 for (XmlRpc::XmlRpcValue::iterator it = config.begin();
00075 it != config.end(); ++it)
00076 {
00077 if (it->second.getType() == XmlRpc::XmlRpcValue::TypeArray)
00078 {
00079 std::string frame_id = (std::string)(it->first);
00080 masks_[frame_id] = std::vector<size_t>();
00081 try
00082 {
00083 for (size_t i = 0; i < it->second.size(); ++i)
00084 {
00085 size_t id = static_cast<int>(it->second[i]);
00086 masks_[frame_id].push_back(id);
00087 }
00088 ROS_INFO("LaserScanMaskFilter: %s: %d directions will be masked.",
00089 frame_id.c_str(), (int)masks_[frame_id].size());
00090 }
00091 catch(XmlRpc::XmlRpcException &e)
00092 {
00093 ROS_ERROR("LaserScanMaskFilter: %s", e.getMessage().c_str());
00094 return false;
00095 }
00096 }
00097 }
00098 return true;
00099 }
00100
00101 virtual ~LaserScanMaskFilter()
00102 {
00103 }
00104
00105 bool update(const sensor_msgs::LaserScan& data_in, sensor_msgs::LaserScan& data_out)
00106 {
00107 data_out = data_in;
00108 if (masks_.find(data_out.header.frame_id) == masks_.end())
00109 {
00110 ROS_WARN("LaserScanMaskFilter: frame_id %s is not registered.",
00111 data_out.header.frame_id.c_str());
00112 return true;
00113 }
00114
00115 const std::vector<size_t> &mask = masks_[data_out.header.frame_id];
00116 const size_t len = data_out.ranges.size();
00117 for (std::vector<size_t>::const_iterator it = mask.begin();
00118 it != mask.end(); ++it)
00119 {
00120 if (*it > len) continue;
00121 data_out.ranges[*it] = std::numeric_limits<float>::quiet_NaN();
00122 }
00123
00124 return true;
00125 }
00126 };
00127
00128 }
00129
00130 #endif // LASER_FILTERS_SCAN_MASK_FILTER_H