ROS2 Transform Trees and Odometry#

Learning Objectives#

In this example, we will learn to

  • Add a TF publisher to publish the camera positions as part of the TF tree.

  • Publish relative poses of objects.

  • Publish the odometry of a robot.

  • Use the menu shortcut to create TF and Odometry publishers.

  • View the TF tree in Isaac Sim.

Getting Started#

Important

Make sure to source your ROS 2 installation from the terminal before running Isaac Sim. If sourcing ROS 2 is a part of your bashrc then Isaac Sim can be run directly.

Prerequisite

TF Tree Publisher#

TF Publisher#

Assuming you’ve already gone through the ROS2 camera tutorial and have two cameras on stage already, let’s add those cameras to a TF tree, so that we can track the camera’s position in the global frame.

  1. In a new or existing Action Graph window, add a ROS2 Publish Transform Tree node, and connect it up with On Playback Tick and Isaac Read Simulation Time, like the image below.

  2. In the Property tab for the ROS2 Publish Transform Tree node, add both Camera_1 and Camera_2 to the targetPrims field.

  3. Examine the transform tree in a ROS2-enabled terminal: ros2 topic echo /tf. You should find both cameras on the TF tree. Move the camera around inside the viewport and see how the camera’s pose changes.

Turtlebot TF Graph

Articulation Transforms#

To get the transforms of each linkage on an articulated robot, add the robot’s articulation root to the targetPrims field. All the linkages subsequent to the articulation root will be published automatically. Add /World/turtlebot3_burger to the targetPrims field, and see that the transforms of all the links of the robot, fixed or articulated, will be published on the /tf topic.

Important

If you find that the generated tf tree for an articulated robot chose the wrong link as the root link, use the following step to manually select the articulation root link. This is commonly seen when importing robots using the URDF Importer with “Merge Fixed Link” checked, as well as for mobile robots.

  • Select the robot’s root prim on the Stage Tree, in its “Raw USD Properties” tab, find the “Articulation Root” Section. Delete it by click on the “X” on the right upper corner inside the section.

  • Select the desired link on the Stage Tree, inside its “Raw USD Properties” Tab, click on the +ADD button, and add Physics > Articulation Root.

Publish Relative Transforms#

By default, the transforms are in reference to the world frame. You can check that the /base_link transform of the Turtlebot is published relative to the /World. If you wish to get the transforms relative to something else, such as a camera, make sure to indicate that in the parentPrim field. Add Camera_1 in the parentPrim field, Stop and Play the simulation between property changes, and you can see that the /base_link transform is now relative to Camera_1.

Setting up Odometry#

To setup odometry for a robot, we would need to publish the odometry ROS message as well as its corresponding transforms.

  1. To setup up the odometry publisher, compose an Action Graph that matches the following image.

    ../_images/isaac_tutorial_ros2_odometry_graph.png
    • In the Property tab for the Isaac Compute Odometry Node:

      • Add the Turtlebot prim (ie. /World/turtlebot3_burger) to its Chassis Prim input field. This node calculates the position of the robot relative to its start location. Its output will be fed into both a publisher for the /odom Rostopic, and a TF publisher that publishes the singular transform from /odom frame to /base_link frame.

    • In the Property tab for the ROS2 Publish Raw Transform Tree node:

      • Set the childFrameId input field to base_link.

      • Set the parentFrameId input field to odom. This will now enable publishing odom -> base_link frames in the TF tree.

    • In the Property tab for the ROS2 Publish Odometry node:

      • Set the chassisFrameId input field to base_link.

      • Set the odomFrameId input field to odom. This will now enable publishing odom -> base_link frames in the TF tree.

  2. At this point we are publishing odometry data and our TF tree only consists of odom -> base_link. We would also like to add the robot articulations under base_link to the TF tree. To do this, add a ROS2 Publish Transform Tree node to the graph and attach the Exec In, Context, and Timestamp fields similarly to previous nodes above.

    • In the Property tab for the ROS2 Publish Transform Tree node:

      • Set the targetPrims input field to the path to your Turtlebot Prim (ie. /World/turtlebot3_burger). Ensure it is identical to the prim path set in the Isaac Compute Odometry Node.

      • Set the parentPrim input field to the path to your base_link inside your Turtlebot Prim (ie. /World/turtlebot3_burger/base_link).

  3. Now we should be publishing a TF tree that consists of odom -> base_link -> <other robot links>. This next step is only required when you want to have ground truth localization of the robot. Usually, a ROS package for localization such as Nav2 AMCL would be responsible for setting the transform between a global frame and the odom frame. To setup ground truth localization, add in another ROS2 Publish Raw Transform Tree node to the graph and attach the Exec In, Context, and Timestamp fields similarly to previous nodes above.

    • In the Property tab for the recently added ROS2 Publish Raw Transform Tree node:

      • Set the childFrameId input field to odom.

      • Set the parentFrameId input field to world. This will now enable publishing world -> odom frames in the TF tree.

      • Leave Translation and Rotation fields detached as this will use the defaults of (0.0, 0.0, 0.0) translation vector (XYZ) and (1.0, 0.0, 0.0, 0.0) rotation quaternion (IJKR). This rotation and translation corresponds to the robot’s Start pose. If the robot starts in a different position, these fields would have to be updated accordingly to match that pose.

Your finally graph should look similar to the following:



Hit Play and in a new ROS-sourced terminal run the following command:

ros2 run tf2_tools view_frames

Warning

ROS 2 Foxy is no longer tested or supported. This may result in potential issues when ROS 2 Foxy is used in conjunction with Isaac Sim 4.2 or later.

ros2 run tf2_tools view_frames.py

Open the generated pdf file to see the TF tree that we are publishing from Isaac Sim. It should look similar to the one below.

Note

This command may fail to generate a pdf file on Windows. If this is the case, you can run the command ros2 topic echo /tf to manually check the TFs being published.



For an example of all the publishers and subscribers setup in the Turtlebot ROS2 tutorials, open Isaac/Samples/ROS2/Scenario/turtlebot_tutorial.usd.

Graph Shortcuts#

We provide menu shortcuts to build tf and odometry graphs with just a few clicks.

TF Publisher

For TF Publisher, go to Isaac Utils > Common Omnigraphs > ROS2 TF Publisher` . (If you don’t see any ROS2 graphs listed, you need to first enable the ROS2 bridge). A popup box will appear asking for the parameters needed to populate the graphs. You must provide:

  • the Graph Path and Node Namespaces if you have one

  • the Target Prim that contains the articulation root api if you want to get the full articulation chain in the TF, or the individual prims if you want to publish a single transform of the prim.

  • the parent prim that is used as the reference frame for the transforms. It is defaulted to "/World", but it could be any frame on stage.

If you already have a TF publisher and want to add more prims to publish, as long as they have the same reference prim, then you can check both the “Add to an existing graph” and “Add to an existing node” boxes, give the graph and node paths, and the new target prim to add to the existing graph. If you want to add to the same graph but have different reference prim, it will create a new TF node and use the existing tick, content, and timestamp nodes if they exist.

Odometry Publisher

For Odometry Publisher, go to Isaac Utils > Common Omnigraphs > ROS2 Odometry Publisher. A popup box will appear asking for the parameters needed to populate the graphs. You must provide:

  • the Graph Path and Node Namespaces if you have one

  • the prim that contains the Articulation Root API, and the chassis prim, whose origin is used to calculate odometry.

Viewing the TF tree in Isaac Sim#

The Isaac Sim’s TF Viewer allows to draw, on the simulated scene itself in the viewport window, the TF tree published (under /tf and /tf_static topics) by Isaac Sim and/or external ROS 2 nodes.

  1. To begin, enable the Isaac Sim’s TF Viewer extension using the Extension Manager by searching for omni.isaac.tf_viewer.

  2. Once the extension is enabled, go to the top menu bar and click on Window > TF Viewer to open the TF Viewer control window.

    ../_images/isaac_tutorial_ros2_tf_viewer_window_legend.png

    Window components:

    1. Frame on which to compute the transformations.

    2. Whether the frames (markers) are displayed. Marker color. Marker size (relative).

    3. Whether the frames’ names are displayed. Text color. Text size (relative).

    4. Whether the frames’s axes are displayed (RGB -> XYZ axes). Axis length (in meters). Axis thickness (relative).

    5. Whether to show the connection between the child frames and the parent frames. Line color. Line thickness (relative).

    6. Frame transformation update frequency (Hz). Higher frequency may reduce simulation performance.

    7. Reset transformation tree (clear transformation buffers). Useful to clean TF_OLD_DATA warning, for example.

    Note

    Closing the TF Viewer window will stop the display and clear the viewport drawings.

  3. Choose the appropriate root frame, on which to compute the transformations (e.g: World or world, according to the published TF tree specification), to start the visualization.

    Note

    If the visualization (or a specific root frame) does not show even though there are publications under /tf and/or /tf_static topics:

    1. Make sure the simulation is running before opening the TF Viewer window,

    2. Close and reopen the TF Viewer window to update the TF subscriptions, or

    3. Press the Reset button on the TF Viewer window to reset the transformation tree.

    ../_images/isaac_tutorial_ros2_tf_viewer_example.png

Summary#

This tutorial covered

  • TF publisher to publish sensors and full articulation trees

  • Raw TF publisher to publish individual transforms

  • Odometry publisher and TF publishers setup for Turtlebot

  • Show the TF Viewer in the Isaac Sim’s viewport

Next Steps#

Continue on to the next tutorial in our ROS2 Tutorials series, ROS2 Setting Publish Rates to learn how to set publish rates for ROS2 OmniGraph nodes.