Skip to content

ROS Network Configuration

Trey Fortmuller edited this page Apr 21, 2019 · 2 revisions

Background

ROS allows us to network multiple machines together, all using the same roscore, so that nodes on different vehicles, or a host laptop can all communicate.

This wiki page references material from the ROS wiki pages for Network Setup and Running ROS on Mulitple Machines.

Important Network Properties

  • You only need one master. Select one machine to run it on.
  • All nodes must be configured to use the same master, via ROS_MASTER_URI.
  • There must be complete, bi-directional connectivity between all pairs of machines, on all ports (see ROS/NetworkSetup).
  • Each machine must advertise itself by a name that all other machines can resolve (see ROS/NetworkSetup).

There are three important ROS environment variables that help to control networking behavior:

  1. ROS_MASTER_URI: tells the nodes what address on the network the master is located
  2. ROS_HOSTNAME:
  3. ROS_IP: ROS_IP and ROS_HOSTNAME are optional environment variable that sets the declared network address of a ROS Node or tool. The options are mutually exclusive, if both are set ROS_HOSTNAME will take precedence. Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you are specifying a host name. When a ROS component reports a URI to the master or other components, this value will be used. This setting is only needed in situations where you have multiple addresses for a computer and need to force ROS to a particular one.

Notes

  • to get the hostname of a machine hostname

  • to check if a machine can resolve its own name, on that machine run ping <HOSTNAME> where <HOSTNAME> is the hostname of that machine.

  • to check if a machine can resolve another machine's hostname, on one machine run ping <OTHER_NAME> where <OTHER_NAME> is the hostname of the other machine. Do this for both machines.

  • to find your public IP address on the wireless network you are currently connected to hostname -I

  • to check the status of an environment variable on a machine run echo, and prepend a $ in front of the environment variable name, ex. echo $ROS_MASTER_URI to return the ROS_MASTER_URI environment variable.

  • environment variables persist only for each terminal session, not globally on your system. To get them to persist, add the proper export commands to your .bashrc file.

  • ROS_MASTER_URI has a prefix and a portsuffix, ex: export ROS_MASTER_URI=http://trey-thinkpad:11311

Instructions for the v2v network setup

  1. We use static IPs for all raspberry pis and laptops on the 8 Via Robotics network in the lab configured via the NETGEAR router's administration page: routerlogin.net. The username and password for the router are written on a sticky note attached to the router.

  2. Some fancier routers support "DNS hostname forwarding" but ours does not. So once static IPs have been assigned to all the devices on the network that need to communicate over ROS, each device must have IPs resolved to hostnames manually inside the /etc/hosts file for linux based systems. The lines to add to the /etc/hosts file are in v2v-comm-v2/network_config/hosts.txt. In order to append the hosts.txt file to /etc/hosts run:

cat hosts.txt | sudo tee -a /etc/hosts from the network_config directory of this repo.

Note: this is already done for you in the latest version of the custom v2v raspberry pi image.

  1. Finally, the ROS environment variables for each device must be set appropriately (so all devices present their hostname correctly and so that all devices can locate the master).

A script for setting these environment variables is in v2v-comm-v2/network_config/set_ros_env.sh. To source this shell script every time you open a terminal window, add it to the .bashrc of all devices on the network. This is done already in the v2v pi image, but you'll have to add it to your machine's .bashrc.

vim ~/.bashrc to open the .basrc file in vim

and add the following line (where /PATH/TO/ is the path to this git repo on your machine)

source ~/PATH/TO/v2v-comm-v2/network_config/set_ros_env.sh

Note: a helper script called print_ros_env.sh provided in the same directory echos the environment variables currently set to be sure they've been correctly set if you're unsure.

  1. To confirm ROS is correctly communicating, try running a talker on your local machine (where the ROS core is located), and a listener on a pi.

On your Machine

roscore

rosrun rospy_tutorials talker.py

On the Pi

SSH in to the pi first, then:

rostopic list

The pi should find master and list /chatter as a topic a long with the /rosout logging topics, then

rosrun rospy_tutorials listener.py

The output should start flowing.