@@ -31,19 +31,38 @@ class PointCloudMapper
31
31
nh_priv_.param (" voxel_size" , voxel_size_, 0.1 );
32
32
nh_priv_.param (" filter_map" , filter_map_, false );
33
33
34
- cloud_sub_ = nh_.subscribe <PointCloud>(" input" , 1 , &PointCloudMapper::callback, this );
35
- cloud_pub_ = nh_priv_.advertise <PointCloud>(" output" , 1 , true );
34
+ cloud_sub_ = nh_.subscribe <sensor_msgs::PointCloud2>(" input" , 1 , &PointCloudMapper::callback, this );
35
+ cloud_pub_ = nh_priv_.advertise <sensor_msgs::PointCloud2>(" output" , 1 , true );
36
+
37
+ accumulated_cloud_.header .frame_id = fixed_frame_;
38
+
39
+ ROS_INFO_STREAM (" [PointCloudMapper params:\n " <<
40
+ " \t * Fixed frame: " << fixed_frame_ << " \n " <<
41
+ " \t * Filter map: " << filter_map_ << " \n " <<
42
+ " \t * Filter bounds: " << " ( " << x_filter_min_ << " , " << y_filter_min_ << " , " << z_filter_min_ << " ) and ( " << x_filter_max_ << " , " << y_filter_max_ << " , " << z_filter_max_ << " )" << " \n " <<
43
+ " \t * Voxel size: " << voxel_size_);
44
+
36
45
pub_timer_ = nh_.createWallTimer (ros::WallDuration (3.0 ), &PointCloudMapper::publishCallback, this );
37
46
}
38
47
39
- void callback (const PointCloud::ConstPtr& cloud )
48
+ void callback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg )
40
49
{
41
- ROS_INFO_STREAM (" Received cloud with " << cloud->points .size () << " points." );
50
+ PointCloud cloud;
51
+ pcl::fromROSMsg (*cloud_msg, cloud);
52
+ ROS_INFO_STREAM (" Received cloud with " << cloud.points .size () << " points." );
53
+
42
54
PointCloud transformed_cloud;
43
- ros::Time points_time;
44
- points_time.fromNSec (cloud->header .stamp );
45
- tf_listener_.waitForTransform (fixed_frame_, cloud->header .frame_id , points_time, ros::Duration (5.0 ));
46
- bool success = pcl_ros::transformPointCloud (fixed_frame_, *cloud, transformed_cloud, tf_listener_);
55
+ tf::StampedTransform transform;
56
+ try {
57
+ tf_listener_.waitForTransform (fixed_frame_, cloud_msg->header .frame_id , cloud_msg->header .stamp , ros::Duration (5.0 ));
58
+ tf_listener_.lookupTransform (fixed_frame_, cloud_msg->header .frame_id , cloud_msg->header .stamp , transform);
59
+ } catch (tf::TransformException ex){
60
+ ROS_ERROR (" %s" ,ex.what ());
61
+ ros::Duration (1.0 ).sleep ();
62
+ }
63
+
64
+ pcl_ros::transformPointCloud (cloud, transformed_cloud, tf::Transform (transform));
65
+ bool success = true ;
47
66
if (success)
48
67
{
49
68
accumulated_cloud_ += transformed_cloud;
@@ -71,8 +90,12 @@ class PointCloudMapper
71
90
{
72
91
// Publish the accumulated cloud if last publication was more than 5 seconds before.
73
92
ros::WallDuration elapsed_time = ros::WallTime::now () - last_pub_time_;
74
- if (cloud_pub_.getNumSubscribers () > 0 && elapsed_time.toSec () > 5.0 )
75
- cloud_pub_.publish (accumulated_cloud_);
93
+ if (cloud_pub_.getNumSubscribers () > 0 && elapsed_time.toSec () > 5.0 ) {
94
+
95
+ sensor_msgs::PointCloud2 cloud_msg;
96
+ pcl::toROSMsg (accumulated_cloud_, cloud_msg);
97
+ cloud_pub_.publish (cloud_msg);
98
+ }
76
99
}
77
100
78
101
PointCloud::Ptr filter (PointCloud::Ptr cloud)
0 commit comments