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:
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.
Start the Ubuntu® VM desktop.
Install the Gazebo plugin. See Install Gazebo Plugin Manually in the Perform Co-Simulation Between Simulink and Gazebo example.
Update Gazebo World File
Add the provided world file
Ur10BasicWithPlugin.world
to the directory/home/user/src/GazeboPlugin/world
in the VM.Make two copies of the world file and name them
Ur10BasicWithPlugin_14580.world
andUr10BasicWithPlugin_14581.world
.Edit the value of the
portNumber
tag inUr10BasicWithPlugin_14580.world
to14580
and inUr10BasicWithPlugin_14581.world
to14581
.
Run Gazebo Sessions
Start two Ubuntu terminal sessions in the VM.
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.
Set Network Address to
Custom
.Set Hostname/IP Address to
HOSTNAME
.Set Port number to
PORTNUM
.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