cloud_mapper.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <pcl_ros/point_cloud.h>
00003 #include <pcl_ros/transforms.h>
00004 #include <tf/transform_listener.h>
00005 #include <pcl/point_types.h>
00006 
00011 class CloudMapper
00012 {
00013 public:
00014 
00015   typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloud;
00016 
00017   CloudMapper() :
00018     nh_(), nh_priv_("~")
00019   {
00020     nh_priv_.param("fixed_frame", fixed_frame_, std::string("/map"));
00021     cloud_sub_ = nh_.subscribe<PointCloud>("cloud", 10, &CloudMapper::callback, this);
00022     bool latched = true;
00023     cloud_pub_ = nh_priv_.advertise<PointCloud>("accumulated_cloud", 1, latched);
00024     pub_timer_ = nh_.createTimer(ros::Duration(10.0), &CloudMapper::publishCallback, this);
00025   }
00026 
00027   void callback(const PointCloud::ConstPtr& cloud)
00028   {
00029     ROS_INFO_STREAM("received cloud with " << cloud->points.size() << " points.");
00030     PointCloud transformed_cloud;
00031     bool success = pcl_ros::transformPointCloud(fixed_frame_, *cloud, transformed_cloud, tf_listener_);
00032     if (success)
00033     {
00034       accumulated_cloud_ += transformed_cloud;
00035     }
00036     else
00037     {
00038       ROS_ERROR("Could not transform point cloud to %s", fixed_frame_.c_str());
00039     }
00040     ROS_INFO_STREAM("Map has " << accumulated_cloud_.points.size() << " points.");
00041   }
00042 
00043   void publishCallback(const ros::TimerEvent&)
00044   {
00045     if (cloud_pub_.getNumSubscribers() > 0)
00046     {
00047       cloud_pub_.publish(accumulated_cloud_);
00048     }
00049   }
00050 
00051 private:
00052   ros::NodeHandle nh_;
00053   ros::NodeHandle nh_priv_;
00054 
00055   ros::Subscriber cloud_sub_;
00056   ros::Publisher cloud_pub_;
00057 
00058   ros::Timer pub_timer_;
00059 
00060   std::string fixed_frame_;
00061   tf::TransformListener tf_listener_;
00062   PointCloud accumulated_cloud_;
00063 };
00064 
00065 int main(int argc, char **argv)
00066 {
00067   ros::init(argc, argv, "cloud_mapper");
00068   CloudMapper mapper;
00069   ros::spin();
00070   return 0;
00071 }
00072 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


mapping_tools
Author(s): Stephan Wirth
autogenerated on Thu Apr 18 2013 11:56:23