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

How to visualize TransformStamped in rviz

asked 2021-10-28 06:07:48 -0500

ticotico gravatar image

updated 2021-10-30 17:23:27 -0500

I have a bag with TransformStamped messages that have the following properties:

  • header/frame_id: /world
  • child_frame_id: /body

I would like to visualize this as TF in rviz, but when I add it as TF topic, the TF tree seems empty (as there are no /tf messages?). How can it still visualize it?

* edit => solution: *

thank you so much for your support! The following mini python node publishes a TFMessage which can be displayed in rviz:

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

class TFconverter:
    def __init__(self):
        self.pub_tf = rospy.Publisher("/tf", TFMessage, queue_size=1)
        self.sub_msg = rospy.Subscriber("inTransform", TransformStamped, self.my_callback)

    def my_callback(self, data):
        # self.pub_tf.publish(TFMessage([data]))  # works but no 'nicely readable'

        # clearer
        tf_msg = TFMessage()
        tf_msg.transforms.append(data)
        self.pub_tf.publish(tf_msg)

if __name__ == '__main__':
    rospy.init_node('transform_to_TF_node')
    tfb = TFconverter()
    rospy.spin()
edit retag flag offensive close merge delete

Comments

Does either rosrun rviz rviz /tf:=/outTF work, or just changing "/outTF" to "/tf" and running rviz without topic remapping work?

Also try removing leading slash: "/world" -> "world" (update I just tried this and rviz worked with or without the slash)

rviz will need to be set to use "world" as the Global Options | Fixed frame instead of the default "map", or otherwise a tf tree needs to exist to connect whatever frame rviz is using to world.

lucasw gravatar image lucasw  ( 2021-10-30 08:19:01 -0500 )edit

Yes, that indeed does the trick, thank you so much! So I am now publishing directly on /tf (tf also works, the slash seems somewhat optional). I will adapt the code in the question accordingly and mark it as solved.

ticotico gravatar image ticotico  ( 2021-10-30 17:16:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-28 10:15:10 -0500

lucasw gravatar image

updated 2021-10-30 08:45:23 -0500

If you want to use the regular rviz TF visualization plugin (http://wiki.ros.org/rviz/DisplayTypes/TF) you would need to republish your TransformStamped messages as TFMessage, which contains an array of TransformStampeds so isn't hard to do- you could make a python node to subscribe to TransformStamped and publish as TFMessage. (http://wiki.ros.org/topic_tools/trans... also could work but I find starting a new python node easier than figure out the right transform command line)

Also if for some reason you didn't want to use the /tf or /tf_static topics for your TFMessage topic you could make rviz TF view them like this:

rosrun rviz rviz /tf:=/my_tf_topic /tf_static:=/my_tf_static_topic

(Because the TransformListener used by rviz and the TF plugin is hard-coded to just use /tf and /tf_static, so remapping can force it to use a different topic)


There was an effort to be able to view TransformStampeds as a default rviz plugin but it didn't get merged https://github.com/ros-visualization/...

edit flag offensive delete link more

Comments

Thx! Still having issues...added some info regarding the node above. If using the command rosrun rviz rviz /tf:=/my_tf_topic, I get the following warning: [ERROR] [1635523868.527740874]: Client [/rviz_1635523867255250501] wants topic /my_tf_topic to have datatype/md5sum [tf2_msgs/TFMessage/94810edda583a504dfda3829e70d7eec], but our version has [geometry_msgs/TransformStamped/b5764a33bfeb3588febc2682852579b0]. Dropping connection.

ticotico gravatar image ticotico  ( 2021-10-29 11:13:19 -0500 )edit
1

I phrased that poorly initially, you do need to create a TFMessage and append your transforms into it's tranforms field.

pub_tf.publish([my_transform_stamped]) works but you may want to be more explicit for future readability with pub_tf.publish(TFMessage([my_transform_stamped])) or even

tf_msg = TFMessage()
tf_msg.transforms.append(my_transform_stamped)
pub_tf.publish(tf_msg)
lucasw gravatar image lucasw  ( 2021-10-30 00:08:58 -0500 )edit

awesome, thx a lot! adapted the code in the question accordingly.

ticotico gravatar image ticotico  ( 2021-10-30 17:24:08 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-10-28 06:07:48 -0500

Seen: 971 times

Last updated: Oct 30 '21