Ask Your Question
1

Specification of ROS_MASTER_URI and ROS_HOSTNAME

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

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:

robot1 192.168.1.1
    locally running ros-package: control1 
         subscribing topic2
         publishing  topic1                 

robot2 192.168.1.2
    locally running ros-package: control2
         subscribing topic1
         publishing  topic2

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

export ROS_MASTER_URI=http://192.168.1.1:11311
export ROS_HOSTNAME=192.168.1.1
export ROS_IP=192.168.1.1   
roscore

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

export ROS_MASTER_URI=http://192.1.1.1:11311            
export ROS_IP=192.168.1.2                               
export ROS_HOSTNAME=192.168.1.2

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

Comments

1

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 imagegvdhoorn ( 2017-10-02 08:33:45 -0600 )edit
3

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 imagegvdhoorn ( 2017-10-02 08:34:23 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

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

Subodh Malgonde gravatar image

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

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_MASTER_URI=http://192.168.1.1:11311
export ROS_IP=192.168.1.1   
roscore

On robot 1 (new tab)

export ROS_MASTER_URI=http://192.168.1.1:11311
export ROS_IP=192.168.1.1   
rosrun control1 <node_name>

On robot 2:

export ROS_MASTER_URI=http://192.1.1.1:11311            
export ROS_IP=192.168.1.2
rosrun control2 <node_name>
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 8,438 times

Last updated: Jul 26 '18