map/main.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <stdlib.h>
3 #include <pcl/point_types.h>
4 #include <pcl_ros/point_cloud.h>
5 #include <ros/publisher.h>
6 #include <tf/tf.h>
7 #include <tf/transform_listener.h>
8 #include <sensor_msgs/point_cloud_conversion.h>
9 #include <pcl/filters/voxel_grid.h>
10 #include <pcl/io/pcd_io.h>
11 
12 sensor_msgs::PointCloud2 cloud;
13 ros::Publisher _pointcloud_pub;
14 tf::TransformListener *tf_listener;
15 
16 void nodeCallback(const sensor_msgs::PointCloud2::ConstPtr &msg)
17 {
18  try
19  {
20  sensor_msgs::PointCloud transformed;
21  sensor_msgs::convertPointCloud2ToPointCloud(*msg, transformed);
22  transformed.header.stamp = ros::Time(0);
23  tf_listener->transformPointCloud("/map",transformed,transformed);
24 
25  sensor_msgs::PointCloud2 transformed2;
26  sensor_msgs::convertPointCloudToPointCloud2(transformed, transformed2);
27  sensor_msgs::PointCloud2 output;
28  pcl::concatenatePointCloud(transformed2, cloud, output);
29  cloud = output;
30 
31 // pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
32 // sor.setInputCloud(cloud);
33 // sor.setLeafSize (0.01f, 0.01f, 0.01f);
34 // sor.filter(*cloud);
35 
36 
37 // pcl::PCDWriter w;
38 // w.write("pointcloud_map.pcd", cloud, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(), false);
39  _pointcloud_pub.publish(cloud);
40  }
41  catch (int e)
42  {
43  ROS_ERROR_STREAM("caught error " << e);
44  }
45 }
46 
47 
48 int main(int argc, char** argv)
49 {
50  ros::init(argc, argv, "map");
51 
52  ros::NodeHandle nh;
53  tf_listener = new tf::TransformListener();
54 
55  std::string topics;
56  std::string delimiter = " ";
57 
58  std::list<ros::Subscriber> subs;
59 
60  ros::NodeHandle pNh("~");
61 
62  if(!pNh.hasParam("topics"))
63  ROS_ERROR_STREAM("no param");
64 
65  pNh.getParam("topics", topics);
66 
67  int pos;
68  while((pos = topics.find(delimiter)) != std::string::npos)
69  {
70  std::string token = topics.substr(0, pos);
71  ROS_ERROR_STREAM(token);
72  topics.erase(0,pos+delimiter.length());
73 
74  subs.push_back(nh.subscribe(token, 1, nodeCallback));
75  }
76  ROS_ERROR_STREAM(topics);
77  subs.push_back(nh.subscribe(topics, 1, nodeCallback));
78 
79  cloud.header.frame_id = "/map";
80 
81  _pointcloud_pub = nh.advertise<sensor_msgs::PointCloud2>("/pointcloud/map", 1);
82 
83  tf_listener->waitForTransform("/map", "/lidar", ros::Time(0), ros::Duration(5));
84 
85  ros::spin();
86 }
void nodeCallback(const sensor_msgs::PointCloud2::ConstPtr &msg)
Definition: map/main.cpp:16
sensor_msgs::PointCloud2 cloud
Definition: map/main.cpp:12
ros::Publisher _pointcloud_pub
Definition: map/main.cpp:13
pcl::PointCloud< pcl::PointXYZ > PointCloud
int main(int argc, char **argv)
Definition: map/main.cpp:48
tf::TransformListener * tf_listener
Definition: map/main.cpp:14


igvc
Author(s): Matthew Barulic , Al Chaussee
autogenerated on Sun May 10 2015 16:18:45