-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2.1.3 new feature] 转发lidar_frame坐标系下的点云到world坐标系下
- Loading branch information
Showing
6 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>easondrone_mapping</name> | ||
<version>2.1.2</version> | ||
<version>2.1.3</version> | ||
<description> | ||
A ROS package for mapping via octomap | ||
</description> | ||
|
||
<maintainer email="[email protected]">Eason Hua</maintainer> | ||
<author email="[email protected]">Eason Yi</author> | ||
|
||
<license>Apache</license> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import rospy | ||
import tf2_ros | ||
import tf2_sensor_msgs | ||
from sensor_msgs.msg import PointCloud2 | ||
|
||
class LidarDataTransformer: | ||
def __init__(self): | ||
# Initialize the ROS node | ||
rospy.init_node('pub_pcl_world', anonymous=True) | ||
|
||
# Set up the transform listener | ||
self.tf_buffer = tf2_ros.Buffer() | ||
self.tf_listener = tf2_ros.TransformListener(self.tf_buffer) | ||
|
||
# Subscribe to the PointCloud2 topic | ||
self.pc_subscriber = rospy.Subscriber('/velodyne_points', PointCloud2, self.point_cloud_callback) | ||
|
||
# Publisher for transformed point cloud data | ||
self.pc_publisher = rospy.Publisher('/velodyne_points_world', PointCloud2, queue_size=10) | ||
|
||
def point_cloud_callback(self, msg): | ||
try: | ||
# Look up the transform from 'world' to 'lidar_link' | ||
transform = self.tf_buffer.lookup_transform('world', msg.header.frame_id, rospy.Time(0), rospy.Duration(1.0)) | ||
|
||
# Transform the point cloud to the 'world' frame | ||
transformed_cloud = tf2_sensor_msgs.do_transform_cloud(msg, transform) | ||
|
||
# Publish the transformed point cloud | ||
self.pc_publisher.publish(transformed_cloud) | ||
|
||
except tf2_ros.LookupException as e: | ||
rospy.logerr(f"Transform lookup failed: {e}") | ||
except tf2_ros.ExtrapolationException as e: | ||
rospy.logerr(f"Transform extrapolation failed: {e}") | ||
except Exception as e: | ||
rospy.logerr(f"Error transforming point cloud: {e}") | ||
|
||
def run(self): | ||
rospy.spin() | ||
|
||
if __name__ == '__main__': | ||
try: | ||
transformer = LidarDataTransformer() | ||
transformer.run() | ||
except rospy.ROSInterruptException: | ||
pass |