# How to use two iCub robots in gazebo simulation

## How to use two iCub robots in gazebo simulation¶

In order to use icub robot in gazebo simulation environment one needs to have the repository icub-gazebo and have to set GAZEBO_MODEL_PATH to this repository as indicated in the readme file. Furthermore, icub-gazebo-wholebody repository contains complex gazebo models and gazebo worlds, for example icub-standup-world. In general, these two repositories can be used as standalone or they can be used as a part of robotology-superbuild.

When an iCub model is spawned in gazebo, all the ports that are opened take the name placed in the gazebo_icub_robotname.ini configuration file as a port prefix. The default name used is icubSim:

gazeboYarpPluginsRobotName icubSim

The model name displayed in gazebo is taken iCub from the icub.sdf file and the gazebo-yarp-plugin motor control board ports and ports of the other gazebo-yarp-plugins you placed in your iCub model are opened with the portprefix /icubSim.

If you are trying to put another iCub model in the simulation, it will fail due to the port conflict as it will try to open another set of robot ports with the same port prefix as /icubSim. So, in order to get around this problem, you have to comment out the line gazeboYarpPluginsRobotName icubSim of gazebo_icub_robotname.ini configuration file.

If you are using the two repositories icub-gazebo and icub-gazebo-wholebody as a part of robotology-superbuild you need to build the superbuild and make sure the changes made to gazebo_icub_robotname.ini configuration file are correctly reflected in the install directory.

Now, when a first iCub model is spawned in gazebo it takes the default name of iCub and all the ports related to it are prefixed with /iCub. Similarly, an additional iCub model spawned next to it will have the default name iCub_0 and all the ports related to this new model are prefixed with /iCub_0. In this way multiple robots can be spawned in gazebo simulation environment without any port conflicts.

Another important detail concerns the use of wholeBodyDynamics. In general, wholeBodyDynamics is launched with yarprobotinterface with a configuration file like launch-wholebodydynamics.xml that uses /icubSim port prefix as shown below:

So, in order to use multiple icub robots in gazebo you need to have multiple wholebodydynamics.xml configuration files with port prefixes corresponding to the robots spawned in gazebo.