Connecting to ROS on different machine (a robot)
ROS allows multiple computers to communicate and share topics and services via a local network. This feature is useful for remote testing and simulations, where different ROS nodes can run on multiple machines as if they were on a single computer.
To connect two example machines
- Server (robot) with IP
192.168.68.101and hostnameuav - Client (notebook) with IP
192.168.68.5and hostnamenotebook
you need to setup both the machines followingly.
Server computer (the robot)
Add following lines to ~/.bashrc:
export ROS_MASTER_URI=http://localhost:11311
Add following lines to the /etc/hosts:
192.168.68.5 notebook
Important (skipping these steps may kill ROS on the robot once it disconnects from Wifi):
- Do NOT export
ROS_IPto~/.bashrc. - Remove the server's (the robot's) own hostname in
/etc/hostsexcept of127.0.1.1. More than one instance of192.168.68.101in/etc/hostsis not allowed. The top of the/etc/hostsfile of the robot should look like:
127.0.0.1 localhost
127.0.1.1 uav
192.168.68.101 uav
192.168.68.5 notebook
Client computer (the notebook)
Add following lines to ~/.bashrc:
export ROS_MASTER_URI=http://192.168.68.101:11311
Add following lines to /etc/hosts:
192.168.68.101 uav
Troubleshooting
- Both IPs must be in the same subnet.
- Once you set up accordingly, you should be able to mutually ping the machines using only their hostnames (i.e.,
ping uavfromnotebookand vice versa). - The hostnames must be exact. If the server has hostname
uav, the client must specifyuavand nothing else (e.g.,uav1). In case it mismatches,pingwill work between the machines but ROS topic transfer will NOT work. - There can be multiple clients/servers in
/etc/hosts, but the IPs must be unique. - To be able to run ROS on the client again, set
ROS_MASTER_URIback toexport ROS_MASTER_URI=http://localhost:11311. - For more information, follow to wiki.ros.org/ROS/Tutorials/MultipleMachines.