This tutorial gives an introduction to Ignition Gazebo's service /world/<world name>/create
. This service allows creating entities in the scene such us spheres, lights, etc.
Ignition Gazebo creates many services depending on the plugins that are specified in the SDF. In this case we need to load the UserCommands
plugin, which will offer the create
service. You can include the UserCommands
system plugin including these lines in your SDF:
You can check if this service is available typing:
In one terminal
In another terminal, see if the create service is listed:
Factory message
To create new entities in the world we need to use the ignition::msgs::EntityFactory message to send a request to the create service. This message allows us to create entities from strings, files, Models, Lights or even clone models. This tutorial introduces how to create entities from SDF strings and light messages.
Insert an entity based on a string
We will open an empty Ignition Gazebo world, let's start creating a sphere in the world. In the next snippet you can see how to create models based on strings.
The variable sphereStr
contains the SDF of the model that we want to create in the world. In this case we are creating a sphere of 1 meter of radius in the position: x: 0 y: 0 z: 0.5 roll: 0 pitch: 0 yaw: 0
.
NOTE: You can insert here all kinds of models that can be described using an SDF string.
Then we need to call the service /world/<world_name>/create
:
NOTE: By default, if the entity name does not exist then the entity will be created in the world. On the other hand, if that entity name already exists, then nothing will happen. You may see some traces in the console showing this information. There is an option to create a new entity every time that the message is sent by setting allow_renaming
to true (you can use the method set_allow_renaming()
).
Insert a light
To insert a light in the world we have two options:
- Fill the string inside the
ignition::msgs::EntityFactory
message like in the section above. - Fill the field
light
inside theignition::msgs::EntityFactory
message.
In the following snippet you can see how the light's field is filled.
Or we can create an SDF string:
Please check the API to know which fields are available in the Light message. There are three types of lights: Point, Directional and Spot.
Finally we should call the same service /world/<world_name>/create
: