-
Notifications
You must be signed in to change notification settings - Fork 0
ROS Network Configuration
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.
- 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:
- ROS_MASTER_URI: tells the nodes what address on the network the master is located
- ROS_HOSTNAME:
- 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.
-
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 theROS_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
-
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. -
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 inv2v-comm-v2/network_config/hosts.txt
. In order to append thehosts.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.
- 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.
- 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.
roscore
rosrun rospy_tutorials talker.py
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.