ROS makes it relatively easy for multiple machines to view the same set of topics, services and parameters. This
is particularly useful when your robot's onboard computer is not very powerful since it allows you to run the more demanding processes such as RViz on your desktop.
The Raspberry Pi does not have an internal clock, so it should rely on internet server to keep the time synchronized.
An easy way to keep your computers synchronized is to install the Ubuntu chrony package on both your desktop and your robot. This package will keep your computer clocks synchronized with Internet servers and thus with each other:
sudo apt-get install chrony apt-get update
sudo apt-get install chrony
The chrony daemon will automatically start and begin synchronizing your computer's clock with a number of Internet servers.
ROS Networking using Zeroconf
This is a technique that allows machines on the same subnet to reference each other using local hostnames instead of IP
addresses. It relies on the avahi daemon. It is present by default in the later versions of Ubuntu.
Use the hostname command to determine the short name of your machine.
$ hostname sully
To get the Zeroconf hostname, simply add ".local" after the hostname so in this case, the Zeroconf hostname would be:
Do the same to get the name of your robot:
Make a ping from each computer to the other one and check:
ping sully.local ... ping nemo.local
Setting the ROS_MASTER_URI and ROS_HOSTNAME Variables
On the robot (Nemo) set:
And launch roscore, or the specific script of ROS functionality of Nemo:
And on the desktop PC (Sully):
The ROS_MASTER_URI variable points to your Nemo robot Zeroconf URI.
For an added check on time synchronization, we can run the ntpdate command to synchronize the desktop with the robot:
sudo apt-get install ntpdate sudo ntpdate -b nemo.local
If all goes well, you should be able to see the ROS topics list on your desktop as follows when running:
If you want to make permanent these assignments of the variables, you should add the export lines to the ~/.bashrc file.
Opening New Terminals
In any new terminal window you open on your desktop or robot, you need to set the ROS_HOSTNAME variable to that machine's Zeroconf name.
And for new desktop terminals, you also have to set the ROS_MASTER_URI to point to the robot.
(Or more generally, on any non-master computer, new terminals must set the ROS_MASTER_URI to point to the master computer.)
Running Nodes on both Machines
Now that you have your ROS network set up between your robot and desktop computer, you can run ROS nodes on either machine and both will have access to all topics and services.
The robot's startup files must always be run on robot since these nodes provide drivers to the robot's hardware. This includes the drivers for the robot base and any cameras, laser scanners or other sensors you want to use.
On the other hand, the desktop is a good place to run RViz since it is very CPU-intensive and besides, you'll generally want to monitor your robot from your desktop anyway.