-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathloadMapDbOct
More file actions
51 lines (40 loc) · 1.7 KB
/
loadMapDbOct
File metadata and controls
51 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Publishes the point cloud data extracted from an OpenVSLAM database file.
Read the MessagePack file format and converts it to the ROS PointCloud2 format.
The data is published in the /cloud_in topic, to be used by the octomap server config
"""
import sys, msgpack, rospy, numpy as np
from sensor_msgs.msg import PointCloud2, PointField
from std_msgs.msg import Header
import sensor_msgs.point_cloud2 as pc2
def main(binPath):
rospy.init_node('load_octomap', anonymous=True)
pub = rospy.Publisher('/cloud_in', PointCloud2, queue_size=10)
# Read file as binary and unpack data using MessagePack library
with open(binPath, "rb") as f:
data = msgpack.unpackb(f.read(), use_list=False, raw=False)
# The point data is tagged "landmarks"
landmarks = data["landmarks"]
print("Point cloud has {} points.".format(len(landmarks)))
header = Header()
header.stamp = rospy.Time.now()
header.frame_id = '/map'
points = np.array([pt['pos_w'] for _, pt in landmarks.items()])
fields = [PointField('x', 0, PointField.FLOAT32, 1), \
PointField('y', 4, PointField.FLOAT32, 1), \
PointField('z', 8, PointField.FLOAT32, 1)]
msg = pc2.create_cloud(header=header, fields=fields, points=points)
pub.publish(msg)
print("Finished")
if __name__ == "__main__":
argv = sys.argv
if len(sys.argv) < 2:
print("Convert an OpenVSLAM map database into an octomap file")
print("Each line represents position of landmark like \"x, y, z\"")
print("Usage: ")
print("rosrun autopilot loadMapDbOct [OpenVSLAM map MessagePack file]")
sys.exit()
else:
binPath = sys.argv[1]
main(binPath)