Main Content

Run and Connect to Multiple Gazebo Sessions from Simulink

This example shows how to run multiple Gazebo sessions in a virtual machine (VM) and connect to these sessions simultaneously from Simulink® using the parsim (Simulink) function.

Set Up and Start VM

To follow along with this example:

  1. Download and install the virtual machine with ROS and Gazebo. See Setup Gazebo Simulation Environment in the Perform Co-Simulation Between Simulink and Gazebo example.

  2. Start the Ubuntu® VM desktop.

  3. Install the Gazebo plugin. See Install Gazebo Plugin Manually in the Perform Co-Simulation Between Simulink and Gazebo example.

Update Gazebo World File

  1. Add the provided world file Ur10BasicWithPlugin.world to the directory /home/user/src/GazeboPlugin/world in the VM.

  2. Make two copies of the world file and name them Ur10BasicWithPlugin_14580.world and Ur10BasicWithPlugin_14581.world.

  3. Edit the value of the portNumber tag in Ur10BasicWithPlugin_14580.world to 14580 and in Ur10BasicWithPlugin_14581.world to 14581.

Run Gazebo Sessions

  1. Start two Ubuntu terminal sessions in the VM.

  2. In one terminal, run these commands to launch the first Gazebo session.

cd /home/user/src/GazeboPlugin/export
export SVGA_VGPU10=0
export GAZEBO_MASTER_URI=http://localhost:11340
gazebo ../world/Ur10BasicWithPlugin_14580.world --verbose

3. In the other terminal, run these commands to launch the second Gazebo session.

cd /home/user/src/GazeboPlugin/export
export SVGA_VGPU10=0
export GAZEBO_MASTER_URI=http://localhost:11341
gazebo ../world/Ur10BasicWithPlugin_14581.world --verbose

Update IP Address and Port Number in MATLAB

Open the parsimStart script file.

edit parsimStart.m

Update the ipAddress and port_num variables to match the IP address of the VM and the port numbers of the Gazebo sessions, respectively.

Simulink Model

Open the Simulink model.

open_system("multiGazeboSession.slx")

Configure Gazebo Pacer Block

Before simulating the model, configure Gazebo cosimulation by the Gazebo Pacer block.

open_system("multiGazeboSession/Gazebo Pacer")

Set Reset behavior to Reset Gazebo simulation time and scene.

To configure the connection to the Gazebo simulation, click Configure Gazebo network and simulation settings.

  1. Set Network Address to Custom.

  2. Set Hostname/IP Address to HOSTNAME.

  3. Set Port number to PORTNUM.

  4. Click OK to apply your changes.

Run Simulink Model

Run the parsimStart.m script to initialize the Simulink sessions and run the simulation with parsim.

parsimStart