Adding Obstacles to Simulation World

Sample Obstacles

Participants can download few sample obstacles that may be used in the pre-finale and grand finale rounds from the given zip files:

Extract the contents of the above zip files at: ~/ros2ws/nxp_gazebo/models.

Adding Static Obstacles

Location of obstacles

Participants can add a variety of different types of static/fixed obstacles into the simulation. A large number of sample obstacles are already provided in the software stack stored at ~/ros2ws/osrf/models

Also, after downloading and extracting the contents of the above .zip folders, the participants will have obstacles present at ~/ros2ws/nxp_gazebo/models

Adding obstacles into the simulation world

To add obstacles into the simulation environment, navigate to ~/ros2ws/src/sim_gazebo_bringup/config in the software stack and open the **gen_params.json ****** file.

To add obstacles navigate to the "embedded_models" sub-tag in the "world_params" tag. Now add any number of obstacles by following the example shown:

Please make sure to save the file before running the simulation command and follow proper JSON syntax in the file

Explanation of code:

"embed_model_1": {
					"model": "start_point",
					"name": "start_point_0",
					"pose": "0.2 -0.45 0.09 0 0 0"
  • "embed_model_{x}": Represents a unique identifier tag for each obstacle/model to be spawned in the simulation world. This tag name should be unique for each model to be spawned into the simulation

  • "model": It is the name of the model to be spawned into the simulation. This represents the name of the desired model that has to be spawned and is stored either in ~/ros2ws/nxp_gazebo/models or in ~/ros2ws/osrf/models.

Please make sure the name of the model passed to the "model:" parameter must be case sensitive as well as present in either of the mentioned folders

  • "name": It is a custom unique identifier given to each entity which allows Gazebo to keep track of each model spawned into the simulation.

Use unique string values for the "name" parameter for each obstacle to be added. As same value will not spawn the obstacles into simulation

  • "pose": This parameter defines the position and orientation of models in simulation. It is represented by "x y z R P Y" where: x is x-coordinate, y is y-coordinate, z is z-coordinate, R is roll, P is pitch and Y is yaw.

Adding Moving Obstacles

Creating Custom Plugin

To add moving obstacles into the simulation, the first thing to do is create a custom plugin for each separate obstacle that you wish to animate/ move in the simulation. This custom plugin will help the obstacle/model to move in a fixed path in simulation with fixed time stamps.

Tutorial for to create such plugins is available at:

Tutorial to build and compile custom plugins is available at:

Adding obstacle with the plugin

To add moving obstacles into the simulation navigate to located at ~/ros2ws/nxp_gazebo/worlds **** in the software stack. Navigate to line 115. Below this line use <include> tags to spawn models into simulation and define their properties along with the plugin to be used. A sample is shown below:

Please make sure to provide the full path of the plugin to be used as many times gazebo have problems in locating custom plugin files

Make traffic light change colour during simulation

Download the above zip file and extract the file: in the root folder/dir

While simulation is running, open a new terminal and run the following command:

$ python3

Run the above command only when gazebo has started and initialized succesfully

This script will enable changing of red light to green light (and vice versa) in simulation after 10 seconds interval.

This script is only compatible for sample track given above. If you want to use the script for other locations of red light in the gazebo, world then edit the -x -y -z -R -P -Y values accordingly

Last updated