Issue with ros::Time when using /use_sim_time
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?
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).
Also, how are you setting
/use_sim_time
totrue
? Please include all of the commands that you run instead of paraphrasing