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

Specification of ROS_MASTER_URI and ROS_HOSTNAME

asked 2017-10-02 08:18:33 -0500

JanOr gravatar image

Hello everyone,

I would like to us ros for multiple robot instances, but have some doubts about the network setup. The idea is to have two robots that are communicating in a network. Each of them have seperate control packages that should run local on the robots. However they should be able to send information in the form of the rostopics topic1 and topic2. Accordingly we want to create following setup:

    locally running ros-package: control1 
         subscribing topic2
         publishing  topic1                 

    locally running ros-package: control2
         subscribing topic1
         publishing  topic2

As we need one ros-master to control the communication, we choose as master. Therefore we execute locally on robot 1:

export ROS_IP=   

In order to connect to the ROS-master, we execute locally on robot2:

export ROS_MASTER_URI=            
export ROS_IP=                               

Afterwards we execute the controllers locally. My question is:

  1. Does the shown workflow lead to the desired behavior (controllers running locally).
  2. Why are the ROS_MASTER_URI and ROS_HOSTNAME defined seperately
  3. Why do we need to specify ROS_IP and ROS_HOSTNAME

Thanks a lot for unravel my confusion.

edit retag flag offensive close merge delete



I hate to just point to documentation, but just to make sure you've seen it: wiki/ROS/NetworkSetup and wiki/ROS/Tutorials/MultipleMachines. That should clear up some of your questions.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-02 08:33:45 -0500 )edit

Also: don't use ROS_HOSTNAME if you're not setting a hostname. Use ROS_IP for that. And don't use them both. If you only have IP addressing, use ROS_IP. If you have a working DNS, use ROS_HOSTNAME.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-02 08:34:23 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-07-26 05:23:02 -0500

Subodh Malgonde gravatar image

updated 2018-07-26 05:24:42 -0500

Question 1 Does the shown workflow lead to the desired behavior (controllers running locally).

Yes, just remove the export ROS_HOSTNAME .. commands on both machines. Read the answer to question 3 to know why.

Question 2 Why are the ROS_MASTER_URI and ROS_HOSTNAME defined seperately

When you run ROS nodes on multiple machines, you need to start just 1 master process. The ROS_MASTER_URI will have the address of the machine on which you will run the master process (which is done by roscore or roslaunch.. commands). So this value should be the same on all machines. Whereas ROS_HOSTNAME or ROS_IP will have the values of the hostname or IP of machine where you will run ROS nodes. So these variables will have different values on all machines.

Question 3 Why do we need to specify ROS_IP and ROS_HOSTNAME?

If a machine reports a hostname that is not addressable by other machines, then you need to set either the ROS_IP or ROS_HOSTNAME environment variables. You don't need to specify both ROS_HOSTNAME and ROS_IP together, both are mutually exclusive. Reproducing the text from the docs:

ROS_IP and ROS_HOSTNAME are optional environment variable that sets the declared network address of a ROS Node or tool. The options are mutually exclusive, if both are set ROS_HOSTNAME will take precedence. Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you are specifying a host name. When a ROS component reports a URI to the master or other components, this value will be used. This setting is only needed in situations where you have multiple addresses for a computer and need to force ROS to a particular one.

Source: ROS/EnvironmentVariables

The setup which will work for you:

On robot 1

export ROS_IP=   

On robot 1 (new tab)

export ROS_IP=   
rosrun control1 <node_name>

On robot 2:

export ROS_MASTER_URI=            
export ROS_IP=
rosrun control2 <node_name>
edit flag offensive delete link more

Question Tools



Asked: 2017-10-02 08:18:33 -0500

Seen: 35,227 times

Last updated: Jul 26 '18