Examples

This folder contains a number of examples demonstrating the features of the pcg_gazebo package. To run the Jupyter notebooks, be sure to install it as

pip install jupyterlab

Model generation

Creating full Gazebo models in Python

In the example on creating Gazebo models in Python, it is demonstrated how to use the tools from the simulation module in order to create simulation entities and can be spawned directly into Gazebo.

Model group generator

In the model group generator example notebook, it is demonstrated how to create a model group abstraction in which the model's parameters are re-calculated each time an instance of the model group is created. This allows using a single representation of the model group generator as an asset and generating its variations as an instance is created.

Model factory

In the model factory example notebook, it is demonstrated how to use the creators module to create parametrized simulation models and spawn them in Gazebo.

Generating models from a YAML configuration file

This examples shows how to define a simulation model as a YAML file and generate static Gazebo models to be stored in your local $HOME/.pcg/models folder. This example requires you to run the script in the examples folder

./gen_model_from_factory_config.sh CONFIG_NAME

where CONFIG_NAME refers to the name of one the files (without the .yaml extension) in the examples/model_factory folder. For example, by running

./gen_model_from_factory_config.sh box_dynamic_model

will generate a box model with mass and moments of inertia and store it in the folder $HOME/.pcg/models/pcg_box_dynamic, including model.config and model.sdf files.

Some YAML files include a batch of model descriptions and therefore will produce multiple Gazebo models in the $HOME/.pcg/models folder.

This example runs the chosen YAML file with the run_model_factory script, that feeds the data into the model factory functions found in the model factory module.

To find out more about how to run the model factory from script, run

run_model_factory -h

To generate the model from the YAML file configuration and spawn it into Gazebo, first start Gazebo as

roslaunch gazebo_ros empty_world.launch

and then use the same CONFIG_NAME to run the script

./spawn_model_from_factory_config.sh CONFIG_NAME
Generating models from template Jinja files

This examples shows how generate an SDF file for a Gazebo model from a Jinja template and store static Gazebo models in your local $HOME/.pcg/models folder. This example requires you to run the script in the examples folder

./gen_model_from_template.sh TEMPLATE_NAME

where TEMPLATE_NAME refers to the name of one the files (without the .yaml extension) in the examples/templates/models folder. For example, by running

./gen_model_from_template.sh pcg_bouncy_ball

will generate single-link spherical model with the necessary settings to allow it to bounce when colliding with another object. The model is per default stored in the folder $HOME/.pcg/models/pcg_bouncy_ball, including model.config and model.sdf files.

To find out more about how to run the Jinja processor from script, run

process_jinja_template -h

This notebook also shows an example on how the kobuki robot (converted to a Jinja template to generate the robot description in SDF format) is processed from its templates and imported as an SimulationModel object that can be edited and spawned into the simulation.

World generation

Dynamically generating worlds from YAML configuration file

The pcg_gazebo package includes not only model creators but also engines that allow creating and placing objects in the world according to pre-defined policies and respecting certain constraints.

The sample configurations that allow worlds to be dynamically created can be found in examples/world_generator/worlds and by running

./launch_pcg_world.sh WORLD_CONFIG_NAME

WORLD_CONFIG_NAME being the name of the world configuration file (without the .yaml extension) in the examples/world_generator/worlds folder. The resulting world file will be stored in $HOME/.pcg/worlds folder.

For example, by calling

./launch_pcg_world.sh bouncing_balls_ode

generates an environment of 40 spheres placed randomly in the 3D world, all of them with the bounce settings enabled so that they will bounce against the ground and each other.

Occupancy grid map generation

Occupancy grid maps can be computed from single models, model groups or worlds using ray tracing. In this notebook it is demonstrated how a grid map can be plotted and stored from a generated world.

Parsers

Parsing xacro files

This example it is shown how to import a xacro file that will be processed, rendered into an URDF file and imported as a SimulationModel object.

List of Jupyter notebooks

Simulation

To run some of the notebooks below you may need to source your current ROS distribution and have Gazebo installed in your system since they will also run the simulation. To source ROS, use

source /opt/ros/$ROS_DISTRO/setup.bash  # You can also replace $ROS_DISTRO by the distro you are using, e.g. melodic

The installation instructions for Gazebo can be found here.

SDF parsers

The examples for the sdf parser is available as Jupyter notebooks. The list can be seen below.

URDF parsers

The examples for the urdf parser is available as Jupyter notebooks. The list can be seen below.

Occupancy grid generation
Task manager