tf2_ros lookup_transform giving wrong transformation
Hello everyone,
I want to get the transform from tool0
frame to base_link
frame of the UR3 robot but I'm having problems.
Below is the code I'm using to get the transform:
#!/usr/bin/env python
import rospy
import tf2_ros
class UR3TfListener(object):
def tfListenerCallback(self, event):
if self.tf_buffer.can_transform('tool0','base_link',rospy.Time(0)):
trans = self.tf_buffer.lookup_transform('tool0','base_link',rospy.Time(0))
else:
rospy.logdebug("Can't transform")
tx = trans.transform.translation.x
ty = trans.transform.translation.y
tz = trans.transform.translation.z
rx = trans.transform.rotation.x
ry = trans.transform.rotation.y
rz = trans.transform.rotation.z
rospy.logdebug("tx: %d, ty: %d, tz: %d, rx: %d, ry: %d, rz: %d", tx, ty, tz, rx, ry, rz)
def __init__(self):
self.tf_buffer = tf2_ros.Buffer()
self.listener = tf2_ros.TransformListener(self.tf_buffer)
rospy.Timer(rospy.Duration(0.1),self.tfListenerCallback)
if __name__ == '__main__':
rospy.init_node('tf_listener', anonymous=False, log_level=rospy.DEBUG)
tf_listener = UR3TfListener()
rospy.spin()
The problem that I'm having is that the transform that I'm getting is something like this
[DEBUG] [1666494690.406768, 199.024000]: tx: 0, ty: 0, tz: 0, rx: 0, ry: 0, rz:0
And the transform shouldn't be 0 as the frames look like following:
Edit 1: /tf and /tf_static echo result
When I run rostopic echo /tf -n 1
I get:
transforms:
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "upper_arm_link"
child_frame_id: "forearm_link"
transform:
translation:
x: -0.24365
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 9.38252996394e-06
w: 0.999999999956
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_left_inner_knuckle_link"
child_frame_id: "robotiq_85_left_finger_tip_link"
transform:
translation:
x: 0.04303959807
y: -0.03759940821
z: 0.0
rotation:
x: 0.0
y: 0.0
z: -1.31530571e-05
w: 0.999999999913
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_base_link"
child_frame_id: "robotiq_85_left_inner_knuckle_link"
transform:
translation:
x: 0.06142
y: 0.0127
z: 0.0
rotation:
x: 0.999999999913
y: -1.31530571e-05
z: -1.36017806871e-18
w: -1.03411553546e-13
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_base_link"
child_frame_id: "robotiq_85_left_knuckle_link"
transform:
translation:
x: 0.05490451627
y: 0.03060114443
z: 0.0
rotation:
x: 0.999999999913
y: -1.31530571e-05
z: -1.36017806871e-18
w: -1.03411553546e-13
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_right_inner_knuckle_link"
child_frame_id: "robotiq_85_right_finger_tip_link"
transform:
translation:
x: 0.04303959807
y: -0.03759940821
z: 0.0
rotation:
x: 0.0
y: 0.0
z: -1.31530571e-05
w: 0.999999999913
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_base_link"
child_frame_id: "robotiq_85_right_inner_knuckle_link"
transform:
translation:
x: 0.06142
y: -0.0127
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 1.31530571e-05
w: 0.999999999913
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "robotiq_85_base_link"
child_frame_id: "robotiq_85_right_knuckle_link"
transform:
translation:
x: 0.05490451627
y: -0.03060114443
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 1.31530571e-05
w: 0.999999999913
-
header:
seq: 0
stamp:
secs: 11
nsecs: 296000000
frame_id: "shoulder_link"
child_frame_id: "upper_arm_link"
transform:
translation:
x: 0.0
y: 0.0
z: 0.0 ...
How did you print or note that transformation? Unfortunately, I don't see any print statement in your code snippet. On the other hand, the code is incomplete. Thus, I can not reproduce it here. Nevertheless, you may try the following sample code: http://wiki.ros.org/tf2/Tutorials/Wri...
I based my code on the tf2 tutorials, also I edited my question and put the entire code.
Please show us the message (including the header) that is being published on /tf.
I updated the question with the messages from
/tf
and/tf_static
and the tf tree