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

Issue with ros::Time when using /use_sim_time

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

JaFeKl gravatar image

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

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 image jayess  ( 2019-07-09 17:20:19 -0500 )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 image jayess  ( 2019-07-09 17:30:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Question Tools

1 follower

Stats

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

Seen: 538 times

Last updated: Jul 09 '19