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
hostname
which is a human-readable name that corresponds to that computer's ip address- name lookup, converts a
name
to an ip address which is then used to connect to the remote computer
- name lookup, converts a
- The
rosmaster
process runs on one computer in the network and coordinates ROS nodes- Nodes contact the
rosmaster
to register their publishers and subscribers - Nodes are then directly connected to each other as needed.
- Nodes contact the
Environment variables
- The
ROS_MASTER_URI
environment variable tells a node where to find therosmaster
- All nodes in the network, when launched, should have the same
ROS_MASTER_URI
in order to communicate on the same ROS network - We will run
rosmaster
on our development computers- Our development computer is always on, so we don't need to change the
ROS_MASTER_URI
when we, for example, turn of the robot (like the turtlebot) - If we wanted the
turtlebot
to be completely independent of the development computer, we would runrosmaster
on 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_HOSTNAME
environment variable contains the address of the node.- When
node A
connects torosmaster
it providesrosmaster
with the value ofROS_HOSTNAME
.rosmaster
uses this address to tell other nodes how to contactnode A
. - If no
ROS_HOSTNAME
is provided, thehostname
of the computer on which the node is running will be used.
- When
- The
ROS_IP
variable is likeROS_HOSTNAME
but 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
hostname
resolution.- This means that every computer in the network can
ping
every other computer byhostname
- This means that every computer in the network can
- The easiest way to get
hostname
resolution working on your network is to use arouter
that sets up name resolution for you automatically- Every computer just connects to the router. You then set
ROS_MASTER_URI
to thehostname
of the comptuer runningrosmaster
- In my experience, openWRT, a Linux distribution for routers sets up
hostname
resolution automatically - When buying routers for use with robotics, I make sure to buy one that
OpenWRT
supports. Most consumer-level routers that I know of do not supporthostname
resolution - I use this setup on the
TURTLENET
network in the lab - You can also assign
static ip addresses
to each computer, and do everything byip
address or byhostnames
written to/etc/hosts
- Every computer just connects to the router. You then set
- The second easiest way is to use
mdns
or multi-cast DNS- This feature is setup automatically on
ubuntu
. It can be used via theavahi-daemon
or 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
ROS
you must set each computer'sROS_HOSTNAME
to<hostname>.local
where<hostname>
is the hostname of that computer - I use this setup with the
turtlebot
that I give you. This works well whenmdns
is working.
- This feature is setup automatically on
- It is also necessary for the remote machine to have
ssh
enabled, and you must be able to login to the remote machine using anssh
key.
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 install
to create theinstall
directoryinstall
directories in ROS are self-contained- You then copy the contents of
install
to the remote comptuer usingrsync
Launchfiles
- Launchfiles can be used to run nodes on remote machine=
- The
<node>
tag in a launchfile has amachine
attribute 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-loader
script. This is a script on the remote machine that sets up theros
environment loader.sh
is what we use on the turtlebot- It essentially
sources
some workspaces and sets upROS_MASTER_URI
andROS_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
ntp
servers and you will not have problems - If however, a computer does not have internet access, for reliability you will have to
run an
ntp
server on your local network to synchronize everything - For the
turtlebot
I have you install an ntp server on your computer. You then configure theturtlebot
to connect to this ntp server, thus synchronizing the times.