-
Notifications
You must be signed in to change notification settings - Fork 3
ROS Networking
ROS can be used across a network, with different nodes running on different computers. One computer should be designated as the "server" computer, which runs the rosmaster server (this program, along with a few others, is started up when you run roscore
). It makes little difference as to which computer runs roscore
, as the server is not a CPU-intensive task. The important thing is for all computers to be configured to look towards the same computer as the server.
ROS is designed to use DNS resolution to map hostnames to ip addresses, but unfortunately the lab's router is incapable of doing DNS resolution for devices on the local network. Therefore, we need to configure each machine via IP addresses, and/or configure our /etc/hosts
files so each machine knows how to map hostnames to IP addresses. We will do a combination of both.
-
ROS_MASTER_URI
- determines where a node should look for the rosmaster server. Every machine (including the server) should set this variable to the ip address (or hostname) of the server. For example, if the server's ip address is192.168.1.123
,ROS_MASTER_URI
should be set tohttp://192.168.1.123:11311
-
ROS_IP
- by default, when a node registers itself with the rosmaster server, it tells the rosmaster server the hostname of the computer the node is running on. However, because DNS resolution doesn't work on our network, nobody will be able to resolve the hostname to the ip address of the computer. To get around this, we set theROS_IP
variable on each computer to the computer's IP address. -
ROS_HOSTNAME
- this overrides the hostname (not IP address) that is registered with the rosmaster server. It mutually exclusive withROS_IP
, and in general should only be used when other computers can resolve your hostname but your computer can't resolve its own hostname. This is very rare, usually you do not want to use this environment variable. UseROS_IP
instead.
Let's say we want to connect our computer to a turtlebot. We'll setup the turtlebot as the rosmaster server, because this will require minimal configuration to setup the first time, and once configured, you will no longer need to modify the turtlebot's configuration.
Open up the turtlebot's ~/.bashrc
file. Insert the following line (replace if it already exists):
export ROS_MASTER_URI="http://$(hostname):11311"
Make sure to source your ~/.bashrc
file!
source ~/.bashrc
What this does is set the turtlebot to look for itself as the rosmaster server. Once this has been done once, you won't need to ever do it again unless someone else messes with the turtlebot's configuration.
First, open up your laptop's ~/.bashrc
file and add the following lines:
export ROS_MASTER_URI="http://<turtlebot_hostname>:11311
ROS_IP=$(ip addr | awk '/inet/ && /<iface>/{sub(/\/.*$/,"",$2); print $2}')
Make sure you replace <turtlebot_hostname>
with the hostname of the turtlebot. It should look something like irll-chris
if the laptop's name is "chris". You can also run the hostname
command on the turtlebot to look it up. You also need to replace <iface>
with the name of your network interface. You can look this up with the ifconfig
command.
Next, open up your /etc/hosts
file and insert the following line at the end. You might need to use sudo to edit the file.
<turtlebot_ip> <turtlebot_hostname>
replace <turtlebot_ip>
and <turtlebot_hostname>
with the ip address and hostname of the turtlebot.
We have now configured our laptop to look towards the turtlebot for the rosmaster server, configured our ROS_IP so the turtlebot's nodes know the ip address of our computer, and we've modified our /etc/hosts
file so we can resolve the turtlebot's hostname.
The roswtf
command is your friend. It will let you know if any nodes are having trouble talking to each other.