Forcing Gazebo to render at fixed intervals or how to record a video of a simulation
I want to be able to get a video of a Gazebo simulation. As far as I can tell, people are doing that by recording their desktop with things like RecordMyDesktop. I don't find this to be very elegant, but more importantly my simulation runs very slow and I want the video to be real-time speed. The reason why the simulation is slow is that I have an external program communicating with a Gazebo plugin. The plugin's OnUpdate() blocks until communication with the external program completes.
To get around this, I wanted to save images from the simulation at every simulation step with the help of a system plugin as described in this tutorial and then convert them into a video with ffmpeg/avconv.
However, I found that the video produced is very choppy. It looks like the plugin's call back function event::Events::ConnectPreRender(boost::bind(&ImagePlugin::Update, this)));
is not actually called at fixed simulation time intervals. This appears to be true even when limiting the simulation by adding the following to the .world
file, which effectively forces the real time factor to be 0.01:
<physics type="ode">
<real_time_update_rate>10.00000</real_time_update_rate>
<max_step_size>0.001000</max_step_size>
</physics>
This also not very satisfactory because with this, the simulation is running at a very conservative speed.
The next thing I tried was to run the simulation and record/log it, then filter the log to get a recording at a given update rate (with the -z argument) and playing that back with the system plugin that records the images:
# run the simulation headlessly and record it
gzserver -r my_scara.world
# filter the log file at 30Hz
gz log -e -f ~/.gazebo/log/*/gzserver/state.log -z 30 --filter *.pose/*.pose > /tmp/filtered_state.log
# run the simulation from the recording and take pictures
gazebo -u -p /tmp/filtered_state.log -g image_plugin/build/libimage_plugin.so
This, however, runs the simulation very quickly and the plugins' Update() function is not executed 30 times per simulation-time second.
So my question is this: What can I do to get an image of the simulation at fixed intervals?
Thanks in advance.