0
$\begingroup$

Rosanswers logo

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()

Originally posted by ticotico on ROS Answers with karma: 212 on 2021-10-28

Post score: 0


Original comments

Comment by lucasw on 2021-10-30:
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.

Comment by ticotico on 2021-10-30:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/transform 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/rviz/issues/428


Originally posted by lucasw with karma: 8729 on 2021-10-28

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by ticotico on 2021-10-29:
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.

Comment by lucasw on 2021-10-30:
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)

Comment by ticotico on 2021-10-30:
awesome, thx a lot! adapted the code in the question accordingly.

$\endgroup$

Your Answer

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