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.
Each of the items above takes precedence over the ones below it. For example, if a the SDF file has any <plugin>
elements, then the GZ_SIM_SERVER_CONFIG_PATH
variable is ignored. And the default configuration file is only loaded if no plugins are passed through the SDF file or the 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 only one system plugin loaded, the scene broadcaster, 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.