Skip to content

Commit c2d2038

Browse files
author
Paul Bovbel
committed
Fix pointcloud to laserscan transform tolerance issues
1 parent 81b472e commit c2d2038

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

include/pointcloud_to_laserscan/pointcloud_to_laserscan_nodelet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include "nodelet/nodelet.h"
4848
#include "tf2_ros/buffer.h"
49+
#include "tf2_ros/transform_listener.h"
4950
#include "tf2_ros/message_filter.h"
5051
#include "message_filters/subscriber.h"
5152
#include "sensor_msgs/PointCloud2.h"
@@ -79,7 +80,8 @@ namespace pointcloud_to_laserscan
7980
ros::Publisher pub_;
8081
boost::mutex connect_mutex_;
8182

82-
tf2_ros::Buffer tf2_;
83+
boost::shared_ptr<tf2_ros::Buffer> tf2_;
84+
boost::shared_ptr<tf2_ros::TransformListener> tf2_listener_;
8385
message_filters::Subscriber<sensor_msgs::PointCloud2> sub_;
8486
boost::shared_ptr<MessageFilter> message_filter_;
8587

launch/sample_node.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<remap from="cloud_in" to="$(arg camera)/depth_registered/points_processed"/>
1616
<remap from="scan" to="$(arg camera)/scan"/>
1717
<rosparam>
18-
target_frame: camera_link # Leave empty to output scan in the pointcloud frame
18+
target_frame: camera_link # Leave disabled to output scan in pointcloud frame
1919
transform_tolerance: 0.01
2020
min_height: 0.0
2121
max_height: 1.0

launch/sample_nodelet.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<remap from="cloud_in" to="$(arg camera)/depth_registered/points_processed"/>
1616
<remap from="scan" to="$(arg camera)/scan"/>
1717
<rosparam>
18-
target_frame: camera_link # Leave empty to output scan in the pointcloud frame
18+
target_frame: camera_link # Leave disabled to output scan in pointcloud frame
1919
transform_tolerance: 0.01
2020
min_height: 0.0
2121
max_height: 1.0

package.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
<description>Converts a 3D Point Cloud into a 2D laser scan. This is useful for making devices like the Kinect appear like a laser scanner for 2D-based algorithms (e.g. laser-based SLAM).</description>
66

77
<maintainer email="[email protected]">Paul Bovbel</maintainer>
8+
<author email="[email protected]">Paul Bovbel</author>
89
<author>Tully Foote</author>
910

1011
<license>BSD</license>
11-
12+
1213
<url type="website">http://ros.org/wiki/perception_pcl</url>
1314
<url type="bugtracker">https://github.com/ros-perception/perception_pcl/issues</url>
1415
<url type="repository">https://github.com/ros-perception/perception_pcl</url>
1516

1617
<buildtool_depend>catkin</buildtool_depend>
17-
18+
1819
<build_depend>message_filters</build_depend>
1920
<build_depend>nodelet</build_depend>
2021
<build_depend>roscpp</build_depend>
@@ -34,4 +35,4 @@
3435
<export>
3536
<nodelet plugin="${prefix}/nodelets.xml"/>
3637
</export>
37-
</package>
38+
</package>

src/pointcloud_to_laserscan_nodelet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace pointcloud_to_laserscan
5555
private_nh_ = getPrivateNodeHandle();
5656

5757
private_nh_.param<std::string>("target_frame", target_frame_, "");
58-
private_nh_.param<double>("tolerance", tolerance_, 0.01);
58+
private_nh_.param<double>("transform_tolerance", tolerance_, 0.01);
5959
private_nh_.param<double>("min_height", min_height_, 0.0);
6060
private_nh_.param<double>("max_height", max_height_, 1.0);
6161

@@ -93,8 +93,9 @@ namespace pointcloud_to_laserscan
9393
// if pointcloud target frame specified, we need to filter by transform availability
9494
if (!target_frame_.empty())
9595
{
96-
message_filter_.reset(new MessageFilter(sub_, tf2_, target_frame_, input_queue_size_, nh_));
97-
message_filter_->setTolerance(ros::Duration(tolerance_));
96+
tf2_.reset(new tf2_ros::Buffer());
97+
tf2_listener_.reset(new tf2_ros::TransformListener(*tf2_));
98+
message_filter_.reset(new MessageFilter(sub_, *tf2_, target_frame_, input_queue_size_, nh_));
9899
message_filter_->registerCallback(boost::bind(&PointCloudToLaserScanNodelet::cloudCb, this, _1));
99100
message_filter_->registerFailureCallback(boost::bind(&PointCloudToLaserScanNodelet::failureCb, this, _1, _2));
100101
}
@@ -132,7 +133,7 @@ namespace pointcloud_to_laserscan
132133
tf2_ros::filter_failure_reasons::FilterFailureReason reason)
133134
{
134135
NODELET_WARN_STREAM_THROTTLE(1.0, "Can't transform pointcloud from frame " << cloud_msg->header.frame_id << " to "
135-
<< message_filter_->getTargetFramesString() << " with tolerance " << tolerance_);
136+
<< message_filter_->getTargetFramesString());
136137
}
137138

138139
void PointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
@@ -176,7 +177,7 @@ namespace pointcloud_to_laserscan
176177
try
177178
{
178179
cloud.reset(new sensor_msgs::PointCloud2);
179-
tf2_.transform(*cloud_msg, *cloud, target_frame_, ros::Duration(tolerance_));
180+
tf2_->transform(*cloud_msg, *cloud, target_frame_, ros::Duration(tolerance_));
180181
cloud_out = cloud;
181182
}
182183
catch (tf2::TransformException ex)

0 commit comments

Comments
 (0)