How to visualize TransformStamped in rviz
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()
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.
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.