ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ros::Time::now() always return wall time in c++

asked 2014-07-22 09:19:14 -0500

proprentnerl gravatar image

updated 2014-07-22 11:26:56 -0500

Hey guys,

I have a very frustrating problem using Ros Hydro on ubuntu 12.04. I have a Gazebo Simulation posting telemetry data and I use this in a node to create a tf-tree for the simulation.

Now I tried to combine my tf-tree with some static transform publishers and noticed that my transform from the c++ node which subscribes to the telemetry is using wall time. The statics transform publishers are using simulation time.

I searched the web, set use_sim_time to true and tried some other things but ros::Time::now() in my c++ code always returns wall time, while the static transform publisher use simulation time! This makes it impossible to use the transform together.

use_sime_time is set before launching any nodes, but my node launches before the /clock topic is available, looking into this next.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-07-23 06:34:12 -0500

proprentnerl gravatar image

Problem solved.

use_sim_time was needed but lead to another problem. The main node was waiting for a service from a python node... when using use_sim_time the main node wouldn't detect the service as long as the /clock service was nit published... Our main node starts the simulation with the /clock service, so doing this first before waiting for the python node service fixed the problem... It seems that python nodes become unresponsive when use_sim_time is activated but no /clock topic is published even when they don't need ans ros::Time functions.

edit flag offensive delete link more

answered 2014-07-22 09:23:28 -0500

demmeln gravatar image

Are you setting use_sim_time before starting the node in questions? Can you check if your node subscribes to the /clock topic?

Please update your question with this information.

edit flag offensive delete link more


Yes use_sim_time is set before starting the node, it seems that my node starts before the /clock topic is available and than continues to use wall time instead of switching to simulation time. I will try waiting for the /clock topic before calling ros::Time::now() in my node.

proprentnerl gravatar image proprentnerl  ( 2014-07-22 11:25:13 -0500 )edit

I believe ros::Time has an explicit method to wait for the simulated clock to be initialized.

ahendrix gravatar image ahendrix  ( 2014-07-22 13:49:03 -0500 )edit
ahendrix gravatar image ahendrix  ( 2014-07-22 13:52:48 -0500 )edit

@proprentnerl: I don't think your theory is correct. If use_sim_time is set, ros::Time::now() will return 0 until it receives the first /clock message, not walltime. This is also the condition that waitForValid() checks for, so that won't fix your problem.

Martin Günther gravatar image Martin Günther  ( 2014-07-23 04:31:57 -0500 )edit

The rospy implementation of tf has some horrible hacks (and bugs) involving walltime, but you mentioned using roscpp, so my guess is that @demmeln is right: your node is started before use_sim_time is set.

Martin Günther gravatar image Martin Günther  ( 2014-07-23 04:33:25 -0500 )edit

Question Tools

1 follower


Asked: 2014-07-22 09:19:14 -0500

Seen: 3,157 times

Last updated: Jul 23 '14