Ask Your Question

roscpp using simulated time

asked 2011-11-30 15:08:50 -0500

William gravatar image

updated 2011-11-30 15:10:53 -0500

I am trying to run gmapping_slam on some old data to improve the position estimate and during my use of the resulting /map -> /odom I realized the stamp on the transforms were using the current walltime rather than the simulated time.

So I setup an experiment to narrow down the cause of this.

I created two simple examples using ros Time in c++ and python:


#!/usr/bin/env python

import roslib; roslib.load_manifest('time_example')
import rospy

def main():

    r = rospy.Rate(5)
    while not rospy.is_shutdown():
        rospy.loginfo("The time is: %f" %

if __name__ == '__main__':


#include "ros/ros.h"

int main(int argc, char **argv) {
  ros::init(argc, argv, "teleop_server");
  ros::NodeHandle n;

  ros::Rate r (5);
  while (ros::ok()) {
    ROS_INFO("The time is: %f", ros::Time::now().toSec());


Then I created a roscore instance:

∫ roscore
... logging to /home/william/.ros/log/1bd2d176-1bd5-11e1-a585-002564acbaae/roslaunch-GDRS-Workstation-16779.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://GDRS-Workstation:53680/
ros_comm version 1.6.5


 * /rosversion
 * /rosdistro


auto-starting new master
process[master]: started with pid [16794]

setting /run_id to 1bd2d176-1bd5-11e1-a585-002564acbaae
process[rosout-1]: started with pid [16807]
started core service [/rosout]

And then in a new terminal I set the use_sim_time parameter with rosparam:

∫ rosparam set use_sim_time 1

In the same terminal I started a bag file I am using.

∫ rosbag play --clock gavlab_and_hallway_2011-04-17-15-09-47.bag 
[ INFO] [1322715599.665805485]: Opening gavlab_and_hallway_2011-04-17-15-09-47.bag

Waiting 0.2 seconds after advertising topics... done.

Hit space to toggle paused, or 's' to step.
 [RUNNING]  Bag Time: 1303070993.265138   Duration: 5.743087 / 715.993344

In a new terminal I ran the Python and then the C++ code:

∫ python nodes/ 
[INFO] [WallTime: 1322714195.471402] [0.000000] The time is: 0.000000
[INFO] [WallTime: 1322714195.857057] [1303071368.690635] The time is: 1303071368.690635
[INFO] [WallTime: 1322714195.857385] [1303071368.690635] The time is: 1303071368.690635
[INFO] [WallTime: 1322714196.055195] [1303071368.892812] The time is: 1303071368.892812
[INFO] [WallTime: 1322714211.060998] [1303071383.899060] The time is: 1303071383.899060
[INFO] [WallTime: 1322714211.257225] [1303071384.091894] The time is: 1303071384.091894
[INFO] [WallTime: 1322714211.453530] [1303071384.294445] The time is: 1303071384.294445
^CTraceback (most recent call last):
  File "nodes/", line 15, in <module>
  File "nodes/", line 12, in main
  File "/opt/ros/electric/stacks/ros_comm/clients/rospy/src/rospy/", line 77, in sleep
    sleep(self.sleep_dur - elapsed)
  File "/opt/ros/electric/stacks/ros_comm/clients/rospy/src/rospy/", line 132, in sleep
    raise rospy.exceptions.ROSInterruptException("ROS shutdown request")
rospy.exceptions.ROSInterruptException: ROS shutdown request
∫ bin/time_example 
[ INFO] [1322714223.326848478]: The time is: 1322714223.326797
[ INFO] [1322714223.526966411]: The time is: 1322714223.526938
[ INFO] [1322714223.726959496]: The time is: 1322714223.726931
[ INFO] [1322714223.926960677]: The time is: 1322714223.926931
[ INFO ...
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2011-11-30 16:10:39 -0500

William gravatar image

So, Python will work with rosparam set use_sim_time 1 but C++ needs rosparam set use_sim_time true. Maybe there should be a warning about this on the wiki or at run time.

edit flag offensive delete link more


That has _got_ to be a bug. If it isn't a bug, it should be. If it shouldn't be a bug, then I need be surgically altered to believe that. I'd open a ticket.
Mac gravatar imageMac ( 2011-11-30 16:15:44 -0500 )edit

This got me just now, too. Was a ticket ever made?

Dave Coleman gravatar imageDave Coleman ( 2014-05-27 23:00:47 -0500 )edit

I guess not, it was before github.

William gravatar imageWilliam ( 2014-05-28 06:25:55 -0500 )edit
Dave Coleman gravatar imageDave Coleman ( 2014-06-09 23:55:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-11-30 15:08:50 -0500

Seen: 4,144 times

Last updated: Nov 30 '11