ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Publish /tf in data ROS2 Dashing with python

asked 2020-04-28 07:05:42 -0600

svintissen gravatar image


I have created a simple .urdf file describing my "robot". I can change the position of the model in the "world_coordinate_system" running "ros2 run tf2_ros static_tranform_publisher" from terminal, describing a transform from "world" to "base_link". ("base_link" describes the model body)

Further I want to create a Node using python that updates the position of the model by publishing the tranform data from "world" to "base_link", but I cant find any good resources on how this is done in ROS2 Dashing.

So far I have tried using geometry_msgs.msg.TransformStamped(), then giving the transform as an input to tf2_msgs.msgTFMessage(), but I cant get it to work.

Do any of you have any examples on how this is done, or a better way to do it?

Thanks in advance, any help as well as links to tutorials or documentation is appriciated!

edit retag flag offensive close merge delete


Have you looked at the tf2 tutorials ?

DanielRobotics gravatar image DanielRobotics  ( 2020-04-28 07:31:58 -0600 )edit

Yes, Ive used the tutorials as a guide, but Im having trouble adapting it to ROS2. Part of the problem Im having is getting the ROS2 equivalent of

svintissen gravatar image svintissen  ( 2020-04-28 07:38:57 -0600 )edit

ROS2 does not have but on your nodes you can use get_clock().now().

DanielRobotics gravatar image DanielRobotics  ( 2020-04-28 08:01:25 -0600 )edit

When I try to use get_clock().now() I get the error "The stamp field must be a sub message of type Time". Why is this? Thanks!

svintissen gravatar image svintissen  ( 2020-04-28 08:06:42 -0600 )edit

You can use get_clock().now().to_msg() which will return the type of header.stamp

DanielRobotics gravatar image DanielRobotics  ( 2020-04-28 08:58:41 -0600 )edit

Thanks, that worked. Still not able to broadcast the transform as the tf2_ros package is not available for ROS2. Any tips as for what I should do instead?

svintissen gravatar image svintissen  ( 2020-04-28 11:24:37 -0600 )edit

Have you installed the package? It's available in all the indexed versions of ROS 2

tfoote gravatar image tfoote  ( 2020-04-28 12:11:41 -0600 )edit

So it is not supported in Dashing, but in eloquent?

svintissen gravatar image svintissen  ( 2020-04-28 13:17:11 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2020-04-30 02:30:18 -0600

svintissen gravatar image

Python bindings for tf2_ros not available in ROS2 Dashing, they are added in Eloquent.

edit flag offensive delete link more


Thanks for filling in the answer here. I've voted it up so you have enough karma to accept your own answer.

tfoote gravatar image tfoote  ( 2020-04-30 02:35:04 -0600 )edit

Hey, for everybody looking this up: It is actually possible in the way you discribe it. Put the "TransformStamped" into a "TFMessage" and publish it under the topic "/tf". You can check via "ros2 topic echo tf".

I was able to get it to work on ROS2 Dashing without the TransformBoradcaster python binding. The TransformBroadcaster is only a really shallow wrapper for publishing a list of transforms with a specific QOS afaik.

Karl gravatar image Karl  ( 2021-01-13 10:36:41 -0600 )edit

answered 2021-01-27 08:17:49 -0600

Karl gravatar image

updated 2021-11-03 05:29:22 -0600

You have to use a list of TFMessage to create the TFMessage. This works for ROS2 Dashing:

from geometry_msgs.msg import TransformStamped
from tf2_msgs.msg import TFMessage

tf_msg = TransformStamped()
# ... do stuff with this transform

# Instead of this:
# broadcaster = TransformBroadcaster(self)
# broadcaster.sendTransform(tf_msg)

# Use this:
publisher = self.create_publisher(msg_type=TFMessage, topic="/tf")
tf_msg = TFMessage()
tf_msg.transforms = [transform_stamped_msg]

This essecially equivalent of the source code of TFBroadcaster in ROS2 Foxy. Tested with ROS2 Dashing and RVIZ. If you want to broadcast a static transform, make sure to use /tf_static and the right QOS TRANSIENT_LOCAL.

edit flag offensive delete link more

Question Tools



Asked: 2020-04-28 07:05:42 -0600

Seen: 2,207 times

Last updated: Nov 03 '21