0
$\begingroup$

Rosanswers logo

I have two nodes who each publish a single static TF2 transform (each with a different child frame) via tf2_ros.StaticTransformBroadcaster.sendTransform upon startup. These are essentially configuration-based transforms; they never change for the entire roscore session. When I later go to read/use these transforms, only one of the two is available (the one which happened to be published second). How can I get access to both of them?

It seems that the StaticTransformBroadcaster merely publishes a tf2_msgs/TFMessage to /tf_static, and by the nature of topics, any previously-latched message is thereby destroyed for future subscribers of that topic. I would have expected StaticTransformBroadcaster to do something more sophisticated -- like: 1) subscribe to /tf_static and receive any existing latched TFMessage 2) whenever a new transform is sent (via StaticTransformBroadcaster.sendTransform), append the new transform to the existing transforms on the latched message it had already received and then 3) publish the union TFMessage to the topic. I suppose I can write this myself, but what is the anticipated use case for the existing StaticTransformBroadcaster? Use only in systems with a single place that ever publishes static transforms, and only ever publishes all static transforms at once? That seems very narrow and I don't see any documentation regarding these limitations apart from reading the source code.

Here is a complete Python script to demo the issue:

import rospy
import tf2_ros
import geometry_msgs.msg

rospy.init_node('tf_test')

br = tf2_ros.StaticTransformBroadcaster()
t = geometry_msgs.msg.TransformStamped()
t.header.stamp = rospy.Time.now()
t.header.frame_id = "world"
t.child_frame_id = "static_camera1"
t.transform.translation.z = 1
t.transform.rotation.w = 1
br.sendTransform(t)

br2 = tf2_ros.StaticTransformBroadcaster()
t2 = geometry_msgs.msg.TransformStamped()
t2.header.stamp = rospy.Time.now()
t2.header.frame_id = "world"
t2.child_frame_id = "static_camera2"
t2.transform.translation.x = 1
t2.transform.rotation.w = 1
br2.sendTransform(t2)

rospy.spin()

With that script running, start RViz and add TF. Observe that only static_camera2 is visible and static_camera1 is hidden. Confirm that the information for static_camera1 is not present in the topic with

rostopic echo /tf_static

Originally posted by BJP on ROS Answers with karma: 100 on 2017-05-15

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Since it's a latched topic it's recommended to only have one Static Transform Publisher per process.

You can resolve this by sending multiple transforms at once via a single broadcaster.

br.sendTransform([t,t2])


Originally posted by tfoote with karma: 58457 on 2017-05-16

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by BJP on 2017-05-17:
That works when t and t2 are generated in a single process, but what about when they are generated in two separate nodes (two separate processes) as in the question? (the demo code is in a single node for brevity)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.