Could not find a connection between 'X' and 'Y' because they are not part of the same tree.Tf has two or more unconnected trees.

asked 2020-02-20 05:22:35 -0500

rosNewbie gravatar image

updated 2022-01-22 16:10:21 -0500

Evgeny gravatar image

I publish a transformation from a c++ Node:

tf2::Transform trans(tfR, tfT);
tf2::Stamped<tf2::Transform> stamped_transform(trans, ros::Time::now(), camera_frame);
geometry_msgs::TransformStamped stamped_transform_msg;
tf2::convert(stamped_transform, stamped_transform_msg);
stamped_transform_msg.child_frame_id = corner_frame;
curr_seq += 1;
stamped_transform_msg.header.seq = curr_seq;
m_transform_msg = stamped_transform_msg;

tf_broadcaster->sendTransform(m_transform_msg);

where corner and camera frame are read from the launch-file:

ros::param::get("camera_frame_name", camera_frame);
ros::param::get("corner_frame_name", corner_frame);

with these values:

<param name="camera_frame_name" value="camera_1" type="str"/>
<param name="corner_frame_name" value="corner" type="str"/>

I try to read this transformation in my python Node like this:

listener1 = transform.TransformListener()
listener1.waitForTransform(self.corner_frame, self.camera_frame1, rospy.Time(), rospy.Duration(4.0))
self.transformations[0] = listener1.lookupTransform(self.corner_frame, self.camera_frame1, rospy.Time(0))

where camera, and corner frame are the same as above.

I get this error messag:

File "/home/tamer/robot_folders/checkout/assembly/catkin_Py3_only_bridge/install/lib/python3/dist-packages/tf/listener.py", line 76, in waitForTransform
    raise tf2_ros.TransformException(error_msg or "no such transformation: \"{}\" -> \"{}\"".format(source_frame, target_frame))
tf2.TransformException: Could not find a connection between 'corner' and 'camera_1' because they are not part of the same tree.Tf has two or more unconnected trees.

When repeating my code to read the transformation after some time it succeeds. But this takes many tries. What am I doing wrong? Why is corner and camera1 not part of the same tree?

Thank you for your help!

edit retag flag offensive close merge delete

Comments

Hi,

First of all I would suggest you to not do this: stamped_transform_msg.header.seq = curr_seq; since the header seq is assigned automatically by the publisher. Set the time stamp instead with ros_time.

On the other hand, it seems you are just publishing a transform between two arbitrary created frames that do not share a common tf tree. Can you check what rosrun rqt_tf_tree rqt_tf_tree displays. It is a good debugging tool to check the state of your tf tree and fix bad connections.

Furthermore, if your goal is to publish a transform that I assume is static, why not using the static_transform_publisher?

Cheers.

Weasfas gravatar image Weasfas  ( 2020-02-20 06:47:27 -0500 )edit

@Weasfas Thanks for the input. I deleted setting the seq as I don't need this anymore anyway. rosrun rqt_tf_tree rqt_tf_tree fails as it gives me an error message check here. I am just very new to ROS. I used the static_transform_publisher now. But doesn't change a thing. Does using the static one means, I just need to publish it one time and it stays published?

rosNewbie gravatar image rosNewbie  ( 2020-02-20 07:28:34 -0500 )edit
1

Hi @rosNewbie

if the transformation camera_frame --> corner_frame is static, E.g. It does not change dynamically depending on your environment actions, it will be sufficient to launch the static_transform E.g. <node pkg="tf" type="static_transform_publisher" name="static_tf" args="0 0 0 0 0 0 camera_frame corner_frame 25"/> that will publish the transform camera_frame --> corner_frame at 25Hz with a transformation of x=0, y=0, z=0, yaw=0, pitch=0, roll=0.

The error you posted is likely due to launching the transform in a bad way like it is said in this post.

Furthermore, this post can be helpful to solve your problem, as well as the tutorials provided for tf2. I bet that this error is due to the fact you do not have a tf buffer.

Weasfas gravatar image Weasfas  ( 2020-02-20 09:10:49 -0500 )edit