$search
00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 00031 #include "ros/ros.h" 00032 #include "sensor_msgs/LaserScan.h" 00033 #include "message_filters/subscriber.h" 00034 #include "tf/message_filter.h" 00035 #include "tf/transform_listener.h" 00036 #include "filters/filter_chain.h" 00037 00038 class GenericLaserScanFilterNode 00039 { 00040 protected: 00041 // Our NodeHandle 00042 ros::NodeHandle nh_; 00043 00044 // Components for tf::MessageFilter 00045 tf::TransformListener tf_; 00046 message_filters::Subscriber<sensor_msgs::LaserScan> scan_sub_; 00047 tf::MessageFilter<sensor_msgs::LaserScan> tf_filter_; 00048 00049 // Filter Chain 00050 filters::FilterChain<sensor_msgs::LaserScan> filter_chain_; 00051 00052 // Components for publishing 00053 sensor_msgs::LaserScan msg_; 00054 ros::Publisher output_pub_; 00055 00056 ros::Timer deprecation_timer_; 00057 00058 public: 00059 // Constructor 00060 GenericLaserScanFilterNode() : 00061 scan_sub_(nh_, "scan_in", 50), 00062 tf_filter_(scan_sub_, tf_, "base_link", 50), 00063 filter_chain_("sensor_msgs::LaserScan") 00064 { 00065 // Configure filter chain 00066 filter_chain_.configure(""); 00067 00068 // Setup tf::MessageFilter for input 00069 tf_filter_.registerCallback(boost::bind(&GenericLaserScanFilterNode::callback, this, _1)); 00070 tf_filter_.setTolerance(ros::Duration(0.03)); 00071 00072 // Advertise output 00073 output_pub_ = nh_.advertise<sensor_msgs::LaserScan>("output", 1000); 00074 00075 deprecation_timer_ = nh_.createTimer(ros::Duration(5.0), boost::bind(&GenericLaserScanFilterNode::deprecation_warn, this, _1)); 00076 } 00077 00078 void deprecation_warn(const ros::TimerEvent& e) 00079 { 00080 ROS_WARN("'generic_laser_filter_node' has been deprecated. Please switch to 'scan_to_scan_filter_chain'."); 00081 } 00082 00083 // Callback 00084 void callback(const sensor_msgs::LaserScan::ConstPtr& msg_in) 00085 { 00086 // Run the filter chain 00087 filter_chain_.update (*msg_in, msg_); 00088 00089 // Publish the output 00090 output_pub_.publish(msg_); 00091 } 00092 }; 00093 00094 int main(int argc, char **argv) 00095 { 00096 ros::init(argc, argv, "scan_filter_node"); 00097 00098 GenericLaserScanFilterNode t; 00099 ros::spin(); 00100 00101 return 0; 00102 }