0
$\begingroup$

Gazebo Answers logo

Hello,

I've been trying to get the GUI Real Time Factor programmatically, and I had various issues trying to do so. Here were a couple things I found from looking around that did not work:

  1. Subscribing to ~/diagnostics: the rtf given by diagnostics seems to be just simtime/realtime so it is the average RTF, not the current RTF. For example, having the simulator at 0.5x for a couple minutes and then putting it to 3x will still give an RTF of 0.5x, slowly converging to 3x. So this is not an option.
  2. Subscribing to ~/world_stats: had no info about rtf; useless
  3. Gz stats. This thing never stops so I don't think I can call it with popen. One dirty workaround I did (that works but not good enough) is popen("gz stats -p -d 1"), which makes gz stats run for 1 second. Ideally, I want a command line arg that'll make gz stat show one line. I tried decimal seconds but those seem to round down (-d 0.5 would just print nothing)
  4. Manually calculating the RTF. I really don't want to do this unless I know the exact formula the Gazebo GUI uses to calculate the RTF. I don't know how long it polls for.

So tl;dr, I either would want to have a way to run gz stats for one line (and not for one second), the exact algorithm/formula that the Gazebo GUI uses to calculate RTF, or any things I am missing (I did look through all Gazebo topics that were published, but I might be missing some compilation flag for extra topics).

Any suggestions? Thanks!


Originally posted by csano on Gazebo Answers with karma: 3 on 2017-06-27

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

I had the same problem and went though basically the same attempted solutions. I eventually re-implemented the same algorithm the gz stats tool uses (similar to your option #4), which can be found here: https://bitbucket.org/osrf/gazebo/src/a24b331f8ebfd712a226ba73b7f43d2d4c14fe15/tools/gz.cc?at=gazebo7&fileviewer=file-view-default#gz.cc-854:916

I was able to work a subscription/callback to world_stats (the above-linked method is such a callback) in to this gazebo_ros_pkgs file, but that may not be applicable to your use case, it was just convenient for me. In fact, there is even a commented-out sub to the same topic seen here.


Originally posted by JLiviero with karma: 94 on 2017-06-27

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by chapulina on 2017-06-27:
This approach is also taken by the gz stats command line tool: https://bitbucket.org/osrf/gazebo/src/ebef2bfd603d4246b0a59b16f0c1374abe19490f/tools/gz.cc?at=default&fileviewer=file-view-default#gz.cc-872

Comment by JLiviero on 2017-06-28:
Ha, you're right @chapulina. I grabbed from my notes quickly and misremembered where in the source it cam from. Edited my post, thanks.

Comment by csano on 2017-06-28:
okay cool! Thanks for the references. So to future readers, it seems like the algorithm in gz stats is to just keep twenty instances of the previous real time and sim time readings from world_stats and then avg(sim_times-sim_times[0])/avg(real_times-real_times[0])

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.