0
$\begingroup$

Rosanswers logo

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:

Python:

#!/usr/bin/env python

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

def main():
    rospy.init_node('time_exmaple')
    
    r = rospy.Rate(5)
    while not rospy.is_shutdown():
        rospy.loginfo("The time is: %f" % rospy.Time.now().to_sec())
        r.sleep()

if __name__ == '__main__':
    main()

C++:

#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());
    ros::spinOnce();
    r.sleep();
  }
  
}

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

SUMMARY
========

PARAMETERS
 * /rosversion
 * /rosdistro

NODES

auto-starting new master
process[master]: started with pid [16794]
ROS_MASTER_URI=http://GDRS-Workstation:11311/

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/time_example.py 
[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
... SHORTENED MANUALLY
[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/time_example.py", line 15, in <module>
    main()
  File "nodes/time_example.py", line 12, in main
    r.sleep()
  File "/opt/ros/electric/stacks/ros_comm/clients/rospy/src/rospy/timer.py", line 77, in sleep
    sleep(self.sleep_dur - elapsed)
  File "/opt/ros/electric/stacks/ros_comm/clients/rospy/src/rospy/timer.py", 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
... SHORTENED MANUALLY
[ INFO] [1322714231.126978724]: The time is: 1322714231.126951
[ INFO] [1322714231.326972936]: The time is: 1322714231.326946
[ INFO] [1322714231.527002318]: The time is: 1322714231.526975
[ INFO] [1322714231.726982139]: The time is: 1322714231.726955

As you can see the Python node is reporting the correct simulated time, and sees the initial time of 0 during the clock initialization period, but the C++ node is reporting the wall time rather than the sim time.

Am I missing something here? Is there another step to make C++ respect the use_sim_time setting?

I am using the latest ROS electric debs on Ubuntu 11.10 x86_64 and I can confirm this is happening on my MacbookPro running the Homebrew based ROS electric source install.

Thanks in advance.


Originally posted by William on ROS Answers with karma: 17335 on 2011-11-30

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by William with karma: 17335 on 2011-11-30

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Mac on 2011-11-30:
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.

Comment by Dave Coleman on 2014-05-27:
This got me just now, too. Was a ticket ever made?

Comment by William on 2014-05-28:
I guess not, it was before github.

Comment by Dave Coleman on 2014-06-09:
I created a ticket here https://github.com/ros/ros_comm/issues/436

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.