0
$\begingroup$

Rosanswers logo

Hi.

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!


Originally posted by svintissen on ROS Answers with karma: 75 on 2020-04-28

Post score: 1


Original comments

Comment by DanielRobotics on 2020-04-28:
Have you looked at the tf2 tutorials http://wiki.ros.org/tf2/Tutorials ?

Comment by svintissen on 2020-04-28:
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 rospy.time.now().

Comment by DanielRobotics on 2020-04-28:
ROS2 does not have rospy.time.now() but on your nodes you can use get_clock().now().

Comment by svintissen on 2020-04-28:
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!

Comment by DanielRobotics on 2020-04-28:
You can use get_clock().now().to_msg() which will return the type of header.stamp

Comment by svintissen on 2020-04-28:
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?

Comment by tfoote on 2020-04-28:
Have you installed the package? It's available in all the indexed versions of ROS 2 https://index.ros.org/p/tf2_ros/#eloquent

Comment by svintissen on 2020-04-28:
So it is not supported in Dashing, but in eloquent?

Comment by tfoote on 2020-04-28:
No, it's available in all ROS 2 versions including Dashing: https://index.ros.org/p/tf2_ros/#dashing I just linked to the default/latest version there are tabs across the top for all the different versions.

Comment by svintissen on 2020-04-29:
Thanks again - Ive installed the package, but I can still not "import tf2_ros" to my python node. Keep gettign "no module named tf2_ros" - any idea what may cause this?

Comment by tfoote on 2020-04-29:
Please edit your question to provide a full overview of how to reproduce your problem. It's mostly likely that you're skipping one or more necessary steps for using the resources. However unless you show us what you're doing we are just going to be guessing. Make sure to include every step including what you did to install things as well as how you're setting up your environment.

Comment by gvdhoorn on 2020-04-29:
@tfoote: isn't the issue here that the Python side of tf2_ros is only available from Eloquent onwards? The OP posted #q350932 in parallel to this one, which links to relevant issues and a discourse post.

Comment by tfoote on 2020-04-29:
Ahh yes. I forgot that the python bindings weren't included in the initial port of the package. They were added in Eloquent.

Comment by svintissen on 2020-04-30:
Okey, I get it - Thanks!

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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


Originally posted by svintissen with karma: 75 on 2020-04-30

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by tfoote on 2020-04-30:
Thanks for filling in the answer here. I've voted it up so you have enough karma to accept your own answer.

Comment by Karl on 2021-01-13:
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.

$\endgroup$
0
$\begingroup$

Rosanswers logo

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]
publisher.publish(tf_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.


Originally posted by Karl with karma: 31 on 2021-01-27

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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