Skip to content

Commit 137418b

Browse files
committed
[v2.1.3 new feature] 转发lidar_frame坐标系下的点云到world坐标系下
1 parent 447907c commit 137418b

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v2.1.3: 2024-08-23
9+
- [new feature] 转发lidar_frame坐标系下的点云到world坐标系下
10+
811
## v2.1.2:
912
- import `message_filters::sync_policies::ApproximateTime` for merge
1013

CMakeLists.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,8 @@ target_link_libraries(pcl_merge
5858
${PCL_LIBRARIES}
5959
)
6060

61-
catkin_install_python(PROGRAMS scripts/laser_to_pointcloud.py
61+
catkin_install_python(PROGRAMS
62+
scripts/laser_to_pointcloud.py
63+
scripts/pub_pcl_world.py
6264
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
6365
)
64-
65-
## Mark other files for installation (e.g. launch and bag files, etc.)
66-
install(DIRECTORY launch
67-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
68-
)
69-
70-
install(DIRECTORY config
71-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
72-
)

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ A ROS package for mapping via octomap.
1212

1313
```bash
1414
cd ~/EasonDrone
15-
catkin_make install --source Reconstruction/EasonDrone_Mapping --build Reconstruction/EasonDrone_Mapping/build
15+
catkin_make --source Reconstruction/EasonDrone_Mapping --build Reconstruction/EasonDrone_Mapping/build
1616
```
1717

18+
## 转发点云
19+
20+
EGO-Planner等规划器要求点云发布在world坐标系下,因此需要将原本发布在lidar_frame的点云转发到world下
21+
22+
```bash
23+
rosrun easondrone_mapping pub_pcl_world.py
24+
```
25+
26+
1827
## 建立地图
1928

2029
```bash

launch/simulation.launch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
<include file="$(find px4ctrl)/launch/px4ctrl.launch"/>
1111

12+
<node name="pub_pcl_world" pkg="easondrone_mapping" type="pub_pcl_world"/>
13+
1214
<!-- 启动octomap建图 -->
1315
<include file="$(find easondrone_mapping)/launch/octomap_server.launch"/>
1416

package.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?xml version="1.0"?>
22
<package format="2">
33
<name>easondrone_mapping</name>
4-
<version>2.1.2</version>
4+
<version>2.1.3</version>
55
<description>
66
A ROS package for mapping via octomap
77
</description>
88

99
<maintainer email="[email protected]">Eason Hua</maintainer>
10-
<author email="[email protected]">Eason Yi</author>
1110

1211
<license>Apache</license>
1312

scripts/pub_pcl_world.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import rospy
5+
import tf2_ros
6+
import tf2_sensor_msgs
7+
from sensor_msgs.msg import PointCloud2
8+
9+
class LidarDataTransformer:
10+
def __init__(self):
11+
# Initialize the ROS node
12+
rospy.init_node('pub_pcl_world', anonymous=True)
13+
14+
# Set up the transform listener
15+
self.tf_buffer = tf2_ros.Buffer()
16+
self.tf_listener = tf2_ros.TransformListener(self.tf_buffer)
17+
18+
# Subscribe to the PointCloud2 topic
19+
self.pc_subscriber = rospy.Subscriber('/velodyne_points', PointCloud2, self.point_cloud_callback)
20+
21+
# Publisher for transformed point cloud data
22+
self.pc_publisher = rospy.Publisher('/velodyne_points_world', PointCloud2, queue_size=10)
23+
24+
def point_cloud_callback(self, msg):
25+
try:
26+
# Look up the transform from 'world' to 'lidar_link'
27+
transform = self.tf_buffer.lookup_transform('world', msg.header.frame_id, rospy.Time(0), rospy.Duration(1.0))
28+
29+
# Transform the point cloud to the 'world' frame
30+
transformed_cloud = tf2_sensor_msgs.do_transform_cloud(msg, transform)
31+
32+
# Publish the transformed point cloud
33+
self.pc_publisher.publish(transformed_cloud)
34+
35+
except tf2_ros.LookupException as e:
36+
rospy.logerr(f"Transform lookup failed: {e}")
37+
except tf2_ros.ExtrapolationException as e:
38+
rospy.logerr(f"Transform extrapolation failed: {e}")
39+
except Exception as e:
40+
rospy.logerr(f"Error transforming point cloud: {e}")
41+
42+
def run(self):
43+
rospy.spin()
44+
45+
if __name__ == '__main__':
46+
try:
47+
transformer = LidarDataTransformer()
48+
transformer.run()
49+
except rospy.ROSInterruptException:
50+
pass

0 commit comments

Comments
 (0)