Hi,
Obtaining the simulation time in the C++ API of ROS should actually be quite simple:
- Code: Select all
ros::Time current_time = ros::Time::now();
Sadly this is only guaranteed to work if you start your ros nodes in the following sequence:
- Have node A start the simulator
- Create a NEW ROS node B
Now you should be able to get the current_time with ros::Time::now() in the code of node B.
The reason is the following excerpt from
http://wiki.ros.org/Clock:
In order for a ROS node to use simulation time according to the /clock topic, the /use_sim_time parameter must be set to true before the node is initialized. This can be done in a launchfile or from the command line.
We publish the simulation time to the ROS /clock topic and set the /use_sim_time parameter to true once the simulation starts. But since each ROS node needs to know the /use_sim_time parameter during initialization you will need to start a new node after simulation start in order to get the timing correctly.
Otherwise you can directly subscribe to the /clock topic or use the timestamps from the telemetry topic as well as the camera topics.