-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplaymapmarkers
44 lines (36 loc) · 1.28 KB
/
displaymapmarkers
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
#!/usr/bin/env python
import sys
import math
import json
import rospy
import tf2_ros
from tf.transformations import quaternion_from_euler
from geometry_msgs.msg import TransformStamped, Vector3
def transform_from_marker(m):
t = TransformStamped()
t.header.frame_id = 'map'
t.child_frame_id = 'aruco/marker' + str(m['id'])
t.transform.translation = Vector3(*m['pose']['position'])
roll, pitch, yaw = m['pose']['orientation']
(t.transform.rotation.x,
t.transform.rotation.y,
t.transform.rotation.z,
t.transform.rotation.w) = quaternion_from_euler(math.radians(roll),
math.radians(pitch),
math.radians(yaw))
return t
def main(argv=sys.argv):
# Let ROS filter through the arguments
args = rospy.myargv(argv=argv)
# Load world JSON
with open(args[1], 'rb') as f:
world = json.load(f)
# Create a transform for each marker
transforms = [transform_from_marker(m) for m in world['markers']]
# Publish these transforms statically forever
rospy.init_node('displaymapmarkers')
broadcaster = tf2_ros.StaticTransformBroadcaster()
broadcaster.sendTransform(transforms)
rospy.spin()
if __name__ == "__main__":
main()