ROS Network Configuration¶
This page describes steps needed to configure network and ROS, so that it can be used to run ROS nodes on different machines. This tutorial assumes that all computers are running Linux, particularly Ubuntu 12.4 LTS. Some of the steps require user to have administrator privileges on all computers. The example network is very simple and consists of two machines. First, Machine A which is used to run ROS master and some additional nodes, this machines is also used for development. Second, Machine B which is used to run vision related nodes (OpenNI drivers and processing).
First of all it is needed that all machines recognise others by a hostname. The hostname for each machine can be set in hosts file which on ubuntu is located at /etc/hosts. If we chose to machine-a and machine-b to be hostnames of the A and B machines respectively, the hosts files for each machine should look like this:
Machine A /etc/hosts:
18.104.22.168 localhost 127.0.0.1 machine-a BBB.BBB.BBB.BBB machine-b
Machine B /etc/hosts:
22.214.171.124 localhost 127.0.0.1 machine-b AAA.AAA.AAA.AAA machine-a
where AAA.AAA.AAA.AAA and BBB.BBB.BBB.BBB are ip addresses of machine A and B respectively. This will allow referencing Machine A as machine-a instead of ip address from both machines and similarly for Machine B.
There are three options to set up users on the machines. First the simplest is to use single user for all people and machines, however this is not encouraged. Second is to use multiple users on all machines this require all people to have user account on all machines. Third is to used dedicated user on machine which is used for development and single user on the other machines. At CTU we chose the last approach.
Hybrid multiple users on master single user on slaves.¶
This setup is desired for such network configurations where some of the computers are used for development and some are just dedicated to computation (a current setup in the CTU lab).
- Create a user on slave machine (B in our case) named ros
- Ensure that every user, who will be using ROS has its SSH public key copied to slave machine (ros@machine-b:/.ssh/authorised_keys)
- Check this configuration by trying SSH form master (Machine A) to slave (Machine B) with ros user (ssh ros@machine-b), you should log in automatically without asking password for ros user. Note that you maight me asked for password for SSH key.
Configure ROS workspace (on slave)¶
In order to be able to launch ROS nodes on slave machine you must create a workspace on the machine under ros user (hybrid setup).
- Follow the steps in CloPeMa Repositories
- Place a s the following script in $HOME/env.sh
#!/usr/bin/env bash # Source the workspace configuration source /home/ros/Source/ROS/setup.bash # Update a workspace (cd /home/ros/Source/ROS/; rosws update) # Kill XnSensorServer in case it is running (required only for OpenNI driver until it is fixed) killall XnSensorServer 2>/dev/null # Execute command exec "$@"
- Make this script executable
chmod +x $HOME/env.sh
Configure ROS (machines file)¶
In order to launch nodes on different machines, these machines must be specified. The machine tag of launch file is used for this purpose.
Machine tag has number of parameters:
- name: Machine name recognised by ROS.
- address: The host name specified in the hosts file
- user: User as which the ros connect to the machine.
- default: Whether is this a default machine.
- env-loader: Path to the *env.sh*Â file.
When the machines are properly set, the machine parameter of node tag can be used. For including launch-files the approach is slightly complicated. The machine must be passed as a parameter (see oppenni.launch in clopema_perception_launch package for example). For onle level inclusion (the included file does not include more files) there is probably easier option (see How to include a .launch file on a remote machine from a .launch file?)
Here is a example cenfiguation
<launch> <machine name="machine-a" address="machine-a" user="$(optenv USER ros)" default="true" env-loader="/home/$(optenv USER ros)/env.sh"/> <machine name="machine-b" address="machine-b" user="ros" env-loader="/home/ros/env.sh"/> <node name="node1" pkg="pkg" machine="machine-b"/> </launch>
Due to some roslaunch error (see answers.ros.org) you must set ROS_MASTER_URI environment variable before running roslaunch: