Remote Nodes
Overview
Nodes in ROS communicate (via topics and services) over a network. Thus ROS nodes need not run on the same computer.
When using ROS to control a mobile robot, there are often at least two comptuers involved: the robot's onboard computer, and the development computer.
The robot's computer typically runs the autonomous systems and the development computer typically runs visualization and diagnostics.
The Network
- Computers running ROS nodes must be able to communicate with each other over a network
- Typically, all computers are on a single local area network (LAN)
- Each computer has a unique IP address, a 4 byte number identifying that computer (e.g., 192.168.0.1).
- Each computer also has a
hostnamewhich is a human-readable name that corresponds to that computer's ip address- name lookup, converts a
nameto an ip address which is then used to connect to the remote computer
- name lookup, converts a
- The
rosmasterprocess runs on one computer in the network and coordinates ROS nodes- Nodes contact the
rosmasterto register their publishers and subscribers - Nodes are then directly connected to each other as needed.
- Nodes contact the
Environment variables
- The
ROS_MASTER_URIenvironment variable tells a node where to find therosmaster- All nodes in the network, when launched, should have the same
ROS_MASTER_URIin order to communicate on the same ROS network - We will run
rosmasteron our development computers- Our development computer is always on, so we don't need to change the
ROS_MASTER_URIwhen we, for example, turn of the robot (like the turtlebot) - If we wanted the
turtlebotto be completely independent of the development computer, we would runrosmasteron theturtlebot
- Our development computer is always on, so we don't need to change the
- All nodes in the network, when launched, should have the same
- The
ROS_HOSTNAMEenvironment variable contains the address of the node.- When
node Aconnects torosmasterit providesrosmasterwith the value ofROS_HOSTNAME.rosmasteruses this address to tell other nodes how to contactnode A. - If no
ROS_HOSTNAMEis provided, thehostnameof the computer on which the node is running will be used.
- When
- The
ROS_IPvariable is likeROS_HOSTNAMEbut contains the ip address of the node. Do not set this if usingROS_HOSTNAME.
Networking setup
- ROS networking is easiest if each computer in the network can connect to the other computers via
hostnameresolution.- This means that every computer in the network can
pingevery other computer byhostname
- This means that every computer in the network can
- The easiest way to get
hostnameresolution working on your network is to use arouterthat sets up name resolution for you automatically- Every computer just connects to the router. You then set
ROS_MASTER_URIto thehostnameof the comptuer runningrosmaster - In my experience, openWRT, a Linux distribution for routers sets up
hostnameresolution automatically - When buying routers for use with robotics, I make sure to buy one that
OpenWRTsupports. Most consumer-level routers that I know of do not supporthostnameresolution - I use this setup on the
TURTLENETnetwork in the lab - You can also assign
static ip addressesto each computer, and do everything byipaddress or byhostnameswritten to/etc/hosts
- Every computer just connects to the router. You then set
- The second easiest way is to use
mdnsor multi-cast DNS- This feature is setup automatically on
ubuntu. It can be used via theavahi-daemonor it is also built-in toNetworkManager/systemd-resolvd. mDNS(by default) automatically lets computers find each other via the addresshostname.local.- To use this with
ROSyou must set each computer'sROS_HOSTNAMEto<hostname>.localwhere<hostname>is the hostname of that computer - I use this setup with the
turtlebotthat I give you. This works well whenmdnsis working.
- This feature is setup automatically on
- It is also necessary for the remote machine to have
sshenabled, and you must be able to login to the remote machine using ansshkey.
Remote Nodes
- To run a remote node, that node and all its runtime dependencies must be on the computer it runs on
- Therefore, you need to copy your nodes to the remote machine before you can run them
- It is easiest to do a
catkin_make installto create theinstalldirectoryinstalldirectories in ROS are self-contained- You then copy the contents of
installto the remote comptuer usingrsync
Launchfiles
- Launchfiles can be used to run nodes on remote machine=
- The
<node>tag in a launchfile has amachineattribute that lets you specify a<machine>on which to run the node - The
<machine>tag in a launchfile lets you specify the address of a remote machine- One important attribute is the
env-loaderscript. This is a script on the remote machine that sets up therosenvironment loader.shis what we use on the turtlebot- It essentially
sourcessome workspaces and sets upROS_MASTER_URIandROS_HOSTNAME
- It essentially
- One important attribute is the
Time Synchronization
- Many ROS packages rely on timestamps indexed to the actual wall-clock time
- Thus, computers on the network must have their clocks synchronized
- If all computers are connected to the internet they will synchronize with
ntpservers and you will not have problems - If however, a computer does not have internet access, for reliability you will have to
run an
ntpserver on your local network to synchronize everything - For the
turtlebotI have you install an ntp server on your computer. You then configure theturtlebotto connect to this ntp server, thus synchronizing the times.