Skip to content

Understanding ROS Time

sh2fong edited this page Feb 19, 2019 · 4 revisions

The following are a compilation of notes that provide an overview of how ROS time works, as well as answers to commonly encountered issues when working with ROS time. The aim of these notes is to address the lack of documentation available online on the topic.

ROSCORE:

  • Launching roscore in a terminal when nothing else is running will not start ros time.
  • You can run roscore without worrying about initializing ros time at an incorrect time

Wall time vs. Sim time:

  • Wall time is the absolute time, or world time i.e. time on your watch
  • Sim time is the time set by your rosbag.

rosbag play and "--clock" argument:

  • When you run rosbag play /path/to/bag/bag_name.bag --clock, it will set the sim time to time that your rosbag recorded. This is usually the wall time that was recorded during your "rosbag record".

  • Your timetamps for all your messages recorded in that bag should has this sim time.

  • When playing back data and using this data for further processing, you want to make sure everything lines up with your timestamps of your bagged messages, so you want to use this sim time.

ROSPARAM /use_sim_time:

  • This ros parameter is used to set the ros time to either the simulation time or the wall time.

Initializing ros vs initialize ros time inside nodes:

There are two options that can be called inside nodes:

  • ros::init()
    • initializes ros and ros time, but does not start the clock
    • if you initialize ros without initializing the ros time, your clock will be zero or
  • ros::Time::init()
    • starts the clock

Possible Initialization Cases:

  1. /use_sim_time false:

    • ros::init() (with or without ros::Time::init())
      • This will initialize your clock with the wall time
      • Doesn't matter if the bag was started or not
    • set /use_sim_time true and rosbag play (with or without --clock)
      • ROS time remains at wall time

Summary: if you initialize ros or ros::Time with the sim time to false, your time will always be wall time until you stop ros (all nodes) and then set the sim time to true and re-init ROS

  1. /use_sim_time true:

    • ros::init()
      • Will not start your ros time (ros time will be 0)
      • ros time will not start until you launch a bag file with the --clock argument
    • ros::init() -> ros::Time::init()
      • Will start your ros time at wall time
      • Once you run your bag with the --clock argument, the ros time will change to the bag time
    • rosbag play --clock + ros::init()
      • Will start ros time and set it to the sim (bag) time
      • If you stop the bag, it will stop the ros time, and your node will stop EVERYTHING. Won't even keep outputting to the terminal
      • If you stop and rerun the bag it will restart the time to the start of the bag time as if you never ran anything before
    • rosbag play --clock + ros::init() + ros::Time::init()
      • Same exact thing as 2c
      • adding the ros::Time::init() did nothing
    • rosbag play -> ros::init()
      • Time will not start (ros time will be 0)
      • You can restart the bag with the --clock arg and it will set the ros time to the bag time.
    • rosbag play -> ros::init() -> ros::Time::init()
      • Time will start at the wall time
      • You can still set the ros time to the bag time by restarting the bag with the --clock argument

Summary: if you set /use_sim_time to true before launching anything, you need to make sure you start the bag with the --clock argument before running any node, or else it will start your ros time at zero (if you do not run ros::Time::init) or to the clock time (if you do set ros::Time::init). If you run another node with the ros::Time::init() that node will still be at the current bag time. This shouldn't mess anything up.

DELETE:

  • If you initialize the ros time before this param is set to true, your ros time will be set to the wall time.
  • If you initialize ros time after always be set to the wall time until you restart your ros master (roscore). You want to make sure you start a roscore, then set this param to true (preferably in a launch file) before you initialize ros time inside any nodes (see next section).

Author: Nick Charron

Last Edited: 18 Feb 2019

Clone this wiki locally