# Get Real Time Factor (RTF) Programmatically?

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.
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!

edit retag close merge delete

Sort by » oldest newest most voted

I had the same problem and went though basically the same attempted solutions. I eventually re-implemented the same algorithm the gz statstool uses (similar to your option #4), which can be found here: https://bitbucket.org/osrf/gazebo/src...

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.

more

Ha, you're right @chapulina. I grabbed from my notes quickly and misremembered where in the source it cam from. Edited my post, thanks.

( 2017-06-28 05:23:38 -0500 )edit

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])

( 2017-06-28 08:32:31 -0500 )edit

~/world_stats has fields sim_time and real_time. The real time factor is sim_time / real_time.

more