ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
2

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

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

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
4

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

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 imageRainMan ( 2018-03-05 07:18:50 -0500 )edit
alidemir gravatar imagealidemir ( 2018-05-25 08:55:28 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 3,306 times

Last updated: Sep 24 '14