Most functionality on Gazebo is provided by plugins, which means that users can choose exactly what functionality is available to their simulations. Even running the physics engine is optional. This gives users great control and makes sure only what's crucial for a given simulation is loaded.
This tutorial will go over how to specify what system plugins to be loaded for a simulation.
How to load plugins
There are a few places where the plugins can be defined:
<plugin>
elements inside an SDF file.- File path defined by the
GZ_SIM_SERVER_CONFIG_PATH
environment variable. - The default configuration file at
$HOME/.gz/sim/<#>/server.config
*, where<#>
is Gazebo Sim's major version.
The behavior of Gazebo when loading these plugins depends on the <include_server_config_plugins>
policy set in <gz:policies>
:
<include_server_config_plugins>true</include_server_config_plugins>
: Plugins in the SDF file are first loaded, followed by plugins from config files (eitherGZ_SIM_SERVER_CONFIG_PATH
or the default configuration file). Plugins from SDF files take precedence over plugins from config files, this means, if a plugin is specified in both places, only the one specified in the SDF file will be loaded. The main use case for this is for users to rely on the default list of plugins and only add extra plugins they need for the application. This is the default setting in Gazebo Ionic and later.<include_server_config_plugins>false</include_server_config_plugins>
: If there are any plugins specified in the SDF file, plugins from the config files (eitherGZ_SIM_SERVER_CONFIG_PATH
or the default configuration file) are ignored. This allows the user to have complete control over which plugins are loaded. This is the default setting in Gazebo Harmonic and earlier.
In both policy settings, the default configuration file is only loaded if no plugins are passed through the GZ_SIM_SERVER_CONFIG_PATH
environment variable.
* For log-playback, the default file is
$HOME/.gz/sim/<#>/playback_server.config
Try it out
Default configuration
Let's try this in practice. First, let's open Gazebo without passing any arguments:
gz sim
You should see an empty world with several systems loaded by default, such as physics, the scene broadcaster (which keeps the GUI updated), and the system that handles user commands like translating models. Try for example inserting a simple shape into simulation and pressing "play":
- the shape is inserted correctly because the user commands system is loaded;
- the shape falls due to gravity because the physics system is loaded;
- and you can see the shape falling through the GUI because the scene broadcaster is loaded.
By default, you're loading this file:
$HOME/.gz/sim/<#>/server.config
That file is created the first time you load Gazebo. Once it is created, Gazebo will never write to it again unless you delete it. This means that you can customize it with your preferences and they will be applied every time Gazebo is started!
Let's try customizing it:
Open this file with your favorite editor:
$HOME/.gz/sim/<#>/server.config
- Remove the
<plugin>
block for the physics system Reload Gazebo:
gz sim
Now insert a shape and press play: it shouldn't fall because physics wasn't loaded.
You'll often want to restore default settings or to use the latest default provided by Gazebo (when you update to a newer version for example). In that case, just delete that file, and the next time Gazebo is started a new file will be created with default values:
rm $HOME/.gz/sim/<#>/server.config
SDF
Let's try overriding the default configuration from an SDF file. Open your favorite editor and save this file as fuel_preview.sdf
:
Now let's load this world:
gz sim -r <path to>/fuel_preview.sdf
Notice how the application has loaded the scene broadcaster, as defined on the SDF file above as well as the default plugins Physics
and UserCommands
. Since SceneBroadcaster
is loaded from the SDF file, it's not loaded again. We see that the cone falls due to gravity since all the necessary plugins are loaded.
Now, let's modify the SDF file to change the policy <include_server_config_plugins>false</include_server_config_plugins>
Let's load this world again:
gz sim -r <path to>/fuel_preview.sdf
Notice how the application has only one system plugin loaded, the SceneBroadcaster
, as defined on the SDF file above. Physics
is not loaded, so even though the simulation is running (started with -r
), the cone doesn't fall with gravity.
If you delete the <plugin>
element from the file above and reload it, you'll see the same model loaded with the default plugins, so it will fall.
Environment variable
It's often inconvenient to embed your plugins directly into every SDF file. But you also don't want to be editing the default config file every time you want to start with a different set of plugins. That's why Gazebo also supports loading configuration files from an environment variable.
Let's start by saving this simple world with a camera sensor as simple_camera.sdf
:
Then load the simple_camera.sdf
world:
gz sim -r <path to>/simple_camera.sdf
You'll see a world with a camera and a cone. If you refresh the image display plugin, it won't show any image topics. That's because the default server configuration doesn't include the sensors system, which is necessary for rendering-based sensors to generate data.
Now let's create a custom configuration file in $HOME/.gz/sim/rendering_sensors_server.config
that has the sensors system:
And point the environment variable to that file:
export GZ_SIM_SERVER_CONFIG_PATH=$HOME/.gz/sim/rendering_sensors_server.config
Now when we launch the simulation again, refreshing the image display will show the camera topic, and we can see the camera data. One interesting thing to notice is that on the camera view, there's no grid and the background color is the default grey, instead of the blue color set on the GUI GzScene
plugin.
Order of Execution of Plugins
The order of execution of plugins can be controlled by setting the <gz:system_priority>
tag inside <plugin>
. See example in examples/plugin/priority_printer_plugin and the associated README.md file to learn more.