Go to the documentation of this file.00001
00051 #include <ros/ros.h>
00052 #include <sensor_msgs/LaserScan.h>
00053
00054 class LaserMaxRangeFilter {
00055 public:
00056 LaserMaxRangeFilter(const std::string & laser_src_topic, const std::string & laser_dst_topic)
00057 {
00058 ROS_DEBUG("LaserMaxRangeFilter('%s' -> '%s')", laser_src_topic.c_str(), laser_dst_topic.c_str());
00059 scan_publisher = n.advertise<sensor_msgs::LaserScan>(laser_dst_topic, 1);
00060 scan_subscriber = n.subscribe(laser_src_topic, 1, &LaserMaxRangeFilter::scan_callback, this);
00061 }
00062
00064
00066 void scan_callback(const sensor_msgs::LaserScan::ConstPtr& scan_src)
00067 {
00068
00069 sensor_msgs::LaserScan scan_dst(*scan_src);
00070 ROS_DEBUG("scan_dst.header.seq:%i, range_min:%g, range_max:%g", scan_dst.header.seq, scan_dst.range_min,
00071 scan_dst.range_max);
00072
00073 float* curr_range = &(scan_dst.ranges[0]);
00074 for (unsigned int idx = 0; idx < scan_dst.ranges.size(); ++idx) {
00075
00076 if (*curr_range <= scan_dst.range_min || *curr_range >= scan_dst.range_max) {
00077
00078 *curr_range = scan_dst.range_max - 1;
00079 }
00080 ++curr_range;
00081 }
00082
00083
00084 scan_publisher.publish(scan_dst);
00085 }
00086
00088
00089 private:
00090 ros::NodeHandle n;
00091 ros::Subscriber scan_subscriber;
00092 ros::Publisher scan_publisher;
00093
00094 };
00095
00097
00098 int main(int argc, char** argv)
00099 {
00100 ros::init(argc, argv, "laser_max_range_filter");
00101
00102 ros::NodeHandle nh("~");
00103
00104 std::string laser_src_topic, laser_dst_topic;
00105
00106 nh.param("laser_src_topic", laser_src_topic, std::string("base_scan"));
00107 nh.param("laser_dst_topic", laser_dst_topic, std::string("base_scan_filtered"));
00108
00109 ROS_DEBUG("laser_max_range_filter:This executable subscribes to a laser scan '%s', "
00110 "and sets all the laser measurements out of range to the max value. "
00111 "It then republishes it to '%s'.",
00112 laser_src_topic.c_str(), laser_dst_topic.c_str());
00113
00114 LaserMaxRangeFilter filter(laser_src_topic, laser_dst_topic);
00115
00121 ros::spin();
00122
00123 return 0;
00124 }