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

Revision history [back]

click to hide/show revision 1
initial version

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.

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>

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>

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>