-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfbroadcaster.py
executable file
·61 lines (46 loc) · 1.93 KB
/
tfbroadcaster.py
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
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import rospy
import tf
from geometry_msgs.msg import PoseStamped, TransformStamped, TwistStamped, Twist, Vector3
t = tf.Transformer()
def tf_broadcaster(msg):
global vel_pub
global t
br = tf.TransformBroadcaster()
br.sendTransform((msg.pose.position.x, msg.pose.position.y, msg.pose.position.z),
(msg.pose.orientation.x,msg.pose.orientation.y,msg.pose.orientation.z,msg.pose.orientation.w),
rospy.Time.now(),
"base_link",
msg.header.frame_id)
br2 = tf.TransformBroadcaster()
br2.sendTransform((0,0,0),
(0,0,0,1),
rospy.Time.now(),
"map",
msg.header.frame_id)
try:
m = TransformStamped()
m.header.frame_id = "map"
m.header.stamp = rospy.Time.now()
m.child_frame_id = "base_link"
m.transform.translation.x = msg.pose.position.x
m.transform.translation.y = msg.pose.position.y
m.transform.translation.z = msg.pose.position.z
m.transform.rotation.x = msg.pose.orientation.x
m.transform.rotation.y = msg.pose.orientation.y
m.transform.rotation.z = msg.pose.orientation.z
m.transform.rotation.w = msg.pose.orientation.w
t.setTransform(m)
[linear,angular] = t.lookupTwist("base_link", "map", rospy.Time(0.0), rospy.Duration(1.001))
twist = TwistStamped()
twist.header.stamp = rospy.Time.now()
twist.twist = Twist(Vector3(linear[0], linear[1], linear[2]), Vector3(angular[0], angular[1], angular[2]))
vel_pub.publish(twist)
except Exception as e:
print 'vel pub error'
# catch *all* exceptions
if __name__ == '__main__':
rospy.init_node('tf')
vel_pub = rospy.Publisher('camera_vel', TwistStamped, queue_size=50)
rospy.Subscriber('camera_pose',PoseStamped,tf_broadcaster)
rospy.spin()