Get Simulation time




Get Simulation time

Postby chloesdaddy » Thu 14. Aug 2014, 23:32

Hi all,

I am sorry, I am new in using ROS, so maybe I ask for a stupid question.

I would like to get the simulation time in the simclient in C++ code.
I succeeded to see the time using : "rostopic echo /euroc_interface_node/lwr_base_to_tcp"

I guess there might be a way but I am not able to find it.

Thank you for your help
chloesdaddy
 
Posts: 8
Joined: Thu 14. Aug 2014, 23:28

by Advertising » Thu 14. Aug 2014, 23:32

Advertising
 

Re: Get Simulation time

Postby michieletto » Sat 16. Aug 2014, 13:21

Hi chloesdaddy,
you can look at the same topic by subscribing it in your C++ code.

ROS Tutorials could help you in finding the right way to do so.
Code: Select all
http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29


I hope this is what you are looking for.

Best.
Stefano
michieletto
 
Posts: 25
Joined: Thu 7. Aug 2014, 12:33
Location: University of Padova

Re: Get Simulation time

Postby chloesdaddy » Sat 16. Aug 2014, 21:21

Hi michieletto,

It helped me. I succeed to get the simulation time.

It was not so trivial as expected but I understand better the use of ROS now.

Thank you for your help
chloesdaddy
 
Posts: 8
Joined: Thu 14. Aug 2014, 23:28

Re: Get Simulation time

Postby Peter Lehner » Mon 18. Aug 2014, 08:20

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.
Peter Lehner
 
Posts: 53
Joined: Fri 27. Jun 2014, 14:33


Return to Stage 1 - Simulation

Who is online

No registered users

cron