Ask Your Question
0

Issue with ros::Time when using /use_sim_time

asked 2019-07-09 16:05:37 -0600

JaFeKl gravatar image

updated 2019-07-09 16:06:35 -0600

Hello everyone,

I have the following issue that ros::Time::now()` always returns zero using the following minimum example.

#include <ros/ros.h>

int main(int argc, char **argv)
{
      ros::init(argc, argv, "force_test_trajectory_pub");     // create ROS node
      while(ros::ok())  {
            beginTime = ros::Time::now();
            ROS_INFO("Starting time %f", beginTime.toSec());
      }
}

The following things are running propperly:

  • I first start roscore as usual
  • Then I set the parameter /use_sim_time to true
  • Then I run gazebo using rosrun gazebo_ros gazebo to get a clock published on /clock
  • Then I run the example above but which only outputs 0 even though /clock is constantly publishing

When I pause Gazebo, the while loop stops as well, which means synchronization is working in some way.

Do you have any suggestion how to fix this problem?

edit retag flag offensive close merge delete

Comments

Can you please update your question so that it includes a minimal reproducible example? That way we don't have to add code to get your example to work (as-is, it won't compile).

jayess gravatar imagejayess ( 2019-07-09 17:20:19 -0600 )edit

Also, how are you setting /use_sim_time to true? Please include all of the commands that you run instead of paraphrasing

jayess gravatar imagejayess ( 2019-07-09 17:30:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-10 04:57:52 -0600

gvdhoorn gravatar image

I would suggest to add something of a sleep or ros::Rate in that while loop.

And a ros::spinOnce(): this is C++, subscriptions are only processed when the queues are spinned.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-09 16:05:37 -0600

Seen: 51 times

Last updated: Jul 09