7.1.4. ROS Clock

7.1.4.1. Learning Objectives

In this example, we will

  • Have a brief discussion on the ROS Clock publisher and subscriber

  • Publish simulation time to ROS as a Clock message

  • Subscribe to a ROS Clock message

7.1.4.2. Getting Started

Prerequisite

  • Completed ROS & ROS 2 Installation: installed ROS, enabled the ROS extension, built the provided Isaac Sim ROS workspace, and set up the necessary environment variables .

  • It is also helpful to have some basic understanding of ROS topics and how publisher and subscriber works.

  • ROS Bridge is enabled.

  • roscore is running.

7.1.4.3. Simulation Time and Clock

In order for external ROS nodes to synchronize with simulation time, a clock topic is usually used. Many ROS nodes such as RViz use the parameter use_sim_time which if set to True will indicate to the node to begin subscribing to the /clock topic and synchronizing to the published simulation time. This parameter can be set using a ROS launch file or the command line interface. We will later see how we can set this parameter in the terminal and observe the effect it has on certain ROS nodes.

7.1.4.4. Running ROS Clock Publisher

  1. Go to Create -> Visual Scripting -> Action Graph to create an Action graph.

  2. Add the following OmniGraph nodes into the Action graph:

  • On Playback Tick node to execute other graph nodes every simulation frame.

  • Isaac Read Simulation Time node to retrieve current simulation time. Note: By default the simulation time increases monotonically, meaning regardless of whether simulation is stopped and re-played, the time will continue incrementing. This is mainly to prevent issues that may aries with the time jumping back when simulation resets. You can set resetOnStop to True if you would like the clock to start from 0 every time simulation is reset.

  • ROS1 Publish Clock node to publish simulation time to the /clock topic.

    ROS Clock publisher
  1. Start RViz in a new ROS-sourced terminal.

    rosrun rviz rviz
    

    Take note of the ROS Time and ROS Elapsed times listed in the bottom of the RViz window. These are currently displaying the wall time and should match the Wall Time and Wall Elapsed fields.

  2. In a new ROS-sourced terminal set the use_sim_time parameter to true for the RViz node using the following command. Ensure that simulation is stopped in Isaac Sim.

    rosparam set /use_sim_time true
    
  3. Close and reopen RViz. Notice this time in RViz that ROS Time and ROS Elapsed are now both 0.

  4. In Isaac Sim click Play. In RViz, the ROS Time is now identical to the simulation time published from Isaac Sim over the /clock topic.

7.1.4.5. Running ROS Clock Subscriber

  1. Open a new stage. Go to Create -> Visual Scripting -> Action Graph to create an Action graph.

  2. Add the following OmniGraph nodes into the Action graph:

  • On Playback Tick node to execute other graph nodes every simulation frame.

  • ROS1 Subscribe Clock node to subscribe to external timestamp data.

    ROS Clock subscriber
  1. Start simulation by clicking Play. Select the ROS1 Subscribe Clock node inside the action graph to view its timeStamp output in the Property window. The timestamp should be currently 0.

  2. In a new ROS-sourced terminal run the following command to manually publish a clock message once:

    rostopic pub  -1 /clock rosgraph_msgs/Clock "clock: { secs: 1, nsecs: 200000000 }"
    

    The timeStamp value in the ROS1 Subscribe Clock OmniGraph node should change to 1.2.

  3. Change the previous command with different secs and nsecs values to see those values being reflected in the timeStamp field of the ROS1 Subscribe Clock OmniGraph node.

7.1.4.6. Summary

This tutorial covered

  1. Explanation for using the /clock topic and the use_sim_time ROS parameter for time synchronization.

  2. Creating and using ROS Clock Publisher and Subscriber nodes.

7.1.4.6.1. Next Steps

Continue on to the next tutorial in our ROS Tutorials series, PhysX Lidar Sensors, to learn how to add a lidar sensor to the Turtlebot3.