Publishing TF2 over ROS2 from a Scene

This tutorial shows how to use multiple instances of a mechanism that publish TF2 in a Vortex® Studio Scene.

Prerequisites

User should have satisfied the prerequisites that are given in the tutorial : Publishing TF2 over ROS2 from a mechanism . It is recommended to have ran the tutorial.

Introduction

First, lets recall that, in ROS2, all nodes across a ROS2 simulation should have different names and that, all TF2's frame ids published must have a unique name.
In regards of those two requirements, when it comes the need to use several instances of a mechanism that are using some ROS2 extensions, some care must be taken in ROS2Node naming and in how frame id are set in Transform Stamped extension if any.

This tutorials will shows how to deal with such use cases.

First step, preparing the scene

  1. Started the Vortex® Studio Editor.
  2. From the main page create a new scene document.
  3. Save it right away under the name 'Scene_2_Hatchback_instances', it will be re-use in some following tutorials.
  4. Right click on the 3DView, select the grid option and choose "Use Grid".
  5. Load twice the mechanism file that has been created from the previous tutorial ( Publishing TF2 over ROS2 from a mechanism ), to do so:
    • Go back to the Editor main page and load the mechanism that was saved in a previous tutorial. Assuming that is has been saved under 'Car - Hatchback - WithTF.vxmechanism'
    • Switch to the Scene Tab
    • From the Toolbox's Basics category, choose "Mechanism From Files" and select the mechanism from the "Opened Resources" list.
    • Do it again.
    • Select the 3D Translation manipulator tool and move the car around ( Manipulating Objects in the 3D View )
    • The scene should now contain two instances of the mechanism file 'Car - Hatchback - WithTF.vxmechanism' at two different positions.

Looking at the issues.

At this point, everything seems fine. But taking a closer look may reveal some problems.

  1. Run the simulation.
  2. Starts a command prompt and source ROS2 as usual.
  3. List the node that are currently running. Here is a screen shot showing the current state of the Editor and the result of the ros2 command.
  4. Running rviz2 and adding TF package will reveal that the published TF2 structure is NOT correct as well.

Fixing the node name and the TF2 issues

As seen in the previous paragraph, there is an issue with the name of the node which appear twice in the ROS2 simulation and that, frame ids are duplicated. To fix those issues do the following.

To handle the fact that several mechanisms may add the same set of frame ids in a ROS2 simulation, Transform Stamped extension uses a strategy to amend the name of their frame ids in a way that has been inspired by the ROS2 topic naming rules. Please, look at the details of this strategy at Setting name for frame ids . But, by the time being, follow the next steps to fix the TF2 issue.

Go to the mechanism document tab (where the Hatchback vehicle is still open) and do the following:

  1. Create a VHL interface.
  2. Give it a name: ROS2 Interface.
  3. Add field to the VHL:
    • From the Explorer panel, double click on the VHL interface.
    • From the Explorer panel, select the Transform Broadcaster extension.
    • In the Property panel, go to the field 'Namespace' and drag it to the parameter section of the VHL.
  4. Save the mechanism file and switch back to the Scene tab.
  5. Select the ROS2 Interface of the first car. Then in the Property panel, edit the 'Namespace' field and set the value to Car1.
  6. Do the same for the second car but use Car2.
  7. Save the file.

What happens is that, the VHL interfaces will forward their respective 'Namespace' value to each of the Transform Broadcaster extension. As a result, by the virtue of ROS2 node naming rule, the two nodes will have a different FQN. Take note that this name is exposed by the output field called 'FQN Node Name' for convenience. This fixes the duplication of node names. This could be verified by running the simulation and running again the ros2 command from a command prompt.

What about the duplication of the frame ids?

As said earlier, Transform Stamped extension uses a strategy to amend the name of their frame ids. Among other, it uses the namespace of the Transform Broadcaster extension that is assigned to it and take it to amend the frame_id. In this particular case, the frame ids are prepended by the namespace of the Transform Broadcaster.

To verify that this, run rviz2 and add TF to it. The result should look like the following:



Conclusion

User has learned how to re-use mechanisms in a scene and to deal with node name and frame id duplication.
We recommend to save the scene that has been authored during this tutorial under the name ''Scene_2_Hatchback_instances.vxscene'. Also save the mechanism file if not already done. They will be re-used in some other tutorials.
Please, follow the next tutorial where users will learn how to add a PointCloud2 Publisher to a mechanism, Publishing Lidar Point Cloud2 data over ROS2 from a Mechanism