Hello everyone, I have a problem with my tf2 transform listener node, I want to get the transform between two frames. This is the code I’m using:
#!/usr/bin/env python
import rospy
import tf2_ros
class UR3TfListener(object):
def __init__(self):
self.tf_buffer = tf2_ros.Buffer()
self.listener = tf2_ros.TransformListener(self.tf_buffer)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
if self.tf_buffer.can_transform('base_footprint','odom',rospy.Time(0)):
trans = self.tf_buffer.lookup_transform('base_footprint','odom',rospy.Time(0))
else:
rospy.logdebug("Can't transform")
rate.sleep()
continue
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)
rate.sleep()
if __name__ == '__main__':
rospy.init_node('tf_listener', anonymous=True, log_level=rospy.DEBUG)
tf_listener = UR3TfListener()
rospy.spin()
The problem is that the result I’m getting are like this:
[DEBUG] [1666494690.406768, 199.024000]: tx: 0, ty: 0, tz: 0, rx: 0, ry: 0, rz:0
And I know the transform shouldn’t be 0 because the frames look like this in Rviz
Image