ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

How to run multiple Independent Gazebo instances on the same machine?

asked 2014-09-19 10:54:08 -0600

Sergio MP gravatar image

Hi all, I'm trying to run multiple independent Gazebo-ROS instances on the same machine so two or more remotely connected users can use it at the same time. I've read this answer about multiple ros masters and this one about multiple Gazebo instances.I've been following them with no success.

I've tried running two ros masters on different ports and launch a gazebo empty_world.launch on each one with different group namespaces as follows:

terminal 1: Run the first ros master: roscore -p 11312

terminal 2: Run test_A.launch: Where test_A.launch is the same as gazebo_ros empty_world.launch but adding a group ns="ns_A" and changing the node names as follows:

<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>
  <arg name="verbose" default="false"/>
  <arg name="world_name" default="worlds/empty.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->

  <!-- set use_sim_time flag -->
  <group if="$(arg use_sim_time)">
    <param name="/use_sim_time" value="true" />
  </group>

  <!-- set command arguments -->
  <arg unless="$(arg paused)" name="command_arg1" value=""/>
  <arg     if="$(arg paused)" name="command_arg1" value="-u"/>
  <arg unless="$(arg headless)" name="command_arg2" value=""/>
  <arg     if="$(arg headless)" name="command_arg2" value="-r"/>
  <arg unless="$(arg verbose)" name="command_arg3" value=""/>
  <arg     if="$(arg verbose)" name="command_arg3" value="--verbose"/>
  <arg unless="$(arg debug)" name="script_type" value="gzserver"/>
  <arg     if="$(arg debug)" name="script_type" value="debug"/>

    <group ns="ns_A">

      <!-- start gazebo server-->
      <node name="gazebo_A" pkg="gazebo_ros" type="gzserver" respawn="false" output="screen"
        args="$(arg command_arg1) $(arg command_arg2) $(arg command_arg3) $(arg world_name)" />

      <!-- start gazebo client -->
      <node name="gazebo_gui_A" pkg="gazebo_ros" type="gzclient" respawn="false" output="screen"></node>

    </group>

</launch>

terminal 3: Run the second ros master: roscore -p 11313

terminal 4: Run test_B.launch: Where test_B.launch is the same as gazebo_ros empty_world.launch but adding a group ns="ns_B" and changing the node names as follows:

<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>
  <arg name="verbose" default="false"/>
  <arg name="world_name" default="worlds/empty.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->

  <!-- set use_sim_time flag -->
  <group if="$(arg use_sim_time)">
    <param name="/use_sim_time" value="true" />
  </group>

  <!-- set command arguments -->
  <arg unless="$(arg paused)" name="command_arg1" value=""/>
  <arg     if="$(arg paused)" name="command_arg1" value="-u"/>
  <arg unless="$(arg headless)" name="command_arg2" value=""/>
  <arg     if="$(arg headless)" name="command_arg2" value="-r"/>
  <arg unless="$(arg verbose)" name="command_arg3" value=""/>
  <arg     if="$(arg verbose)" name="command_arg3" value="--verbose"/>
  <arg unless="$(arg debug)" name="script_type" value="gzserver"/>
  <arg     if="$(arg debug)" name="script_type" value="debug"/>

    <group ns="ns_B">

      <!-- start gazebo server-->
      <node name="gazebo_B" pkg="gazebo_ros" type="gzserver" respawn="false" output="screen"
        args="$(arg command_arg1) $(arg command_arg2) $(arg command_arg3) $(arg ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
6

answered 2014-09-24 11:06:32 -0600

Sergio MP gravatar image

Ok. I finally managed to solve this. I can run now multiple instances of rosmaster and Gazebo!

Since the envioremental variables are "local" to each shell (terminal instance), you need to be careful with this. First, for running different rosmaster instances you need to change the ROS_MASTER_URI enviorement variable for each one. You also need to change the GAZEBO_MASTER_URI for each INDEPENDENT Gazebo instance you want to run. I tried it, and at first it didn't work. That's because according to THIS, you have to edit your /usr/share/gazebo/setup.sh and replace

export GAZEBO_MASTER_URI=http://localhost:11345

for

export GAZEBO_MASTER_URI=${GAZEBO_MASTER_URI:-"http://localhost:11345"}

Then save. If you dont do this change, the GAZEBO_MASTER_URI won't chance properly!!

Now, for running different instances of rosmaster:

First shell:

export ROS_MASTER_URI=http://localhost:11315 11315 is just an example. The default is 11311.
roscore -p 11315 or roslaunch some package. It'll run on the specified port ( localhost:11315 )

Second shell:

export ROS_MASTER_URI=http://localhost:11316 A different one from before!
roscore -p 11316 or roslaunch some package. It'll run on the specified port ( localhost:11316 )

Now, for running multiple Gazebo instances

Third shell:

export GAZEBO_MASTER_URI=http://localhost:11355 11355 is just an example. The default is 11345.

gazebo

Fourth shell:

export GAZEBO_MASTER_URI=http://localhost:11356 A different one from before!

gazebo

And voilà!

edit flag offensive delete link more

Comments

Hello sir, By following your description I am now able to open multiple gazebo instances. But since we are using multiple master node, what is the most effective way to subscribe/publish topics for different gazebo instances?

RainMan gravatar image RainMan  ( 2018-03-05 07:18:50 -0600 )edit
alidemir gravatar image alidemir  ( 2018-05-25 08:55:28 -0600 )edit

Adding an update to this, as a number of people have still had issues with the Gazebo client's using the wrong scene. To fix this, as mentioned here and here, you need to set a unique IGN_PARTITION environment variable value. More information here.

shonigmann gravatar image shonigmann  ( 2022-03-31 19:15:32 -0600 )edit

For Gazebo Garden the environment variables to change is GZ_PARTITION, and for ROS2 Humble, it is ROS_DOMAIN_ID

retinfai gravatar image retinfai  ( 2023-02-16 21:34:02 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2014-09-19 10:54:08 -0600

Seen: 7,440 times

Last updated: Sep 24 '14