-
Notifications
You must be signed in to change notification settings - Fork 3
Running ROS over multiple computers
Although there are good tutorials like:
there still might be some confusion.Say we have 3 computers connected to the same network which for the sake of the example is "11.22.33.0" with network mask of "255.255.255.0". And the hostnames and IP addresses of the 3 computers are:
hostname | comp1 | comp2 | comp3 |
---|---|---|---|
IP | 11.22.33.1 | 11.22.33.2 | 11.22.33.3 |
There should be 1 master/1 ROS core for handling the system. In this example, lets say that comp1 is the master. There is actually nothing much to do other than to just run roscore:
comp1:$ roscore
In the case of slave machines, these need to know the master's IP address. Additionally, ROS is not that smart, meaning that you have to tell the ROS running on the slave machine it's own IP address. That's probably because a computer usually has multiple network interfaces and ROS is not sure about which one is used to communicate with the master. SO:
1) Specify ROS master IP address:
- for comp2: comp2:$ export ROS_MASTER_URI=http://11.22.33.1:11311
- for comp3: comp3:$ export ROS_MASTER_URI=http://11.22.33.1:11311
11311 is the default port of the master. If for some reason it differs from the default value, use the different value accordingly. You can see the port nr. if you run roscore on the master machine.
2) Specify slave machine's own IP:
for comp2: comp2:$ export ROS_IP=11.22.33.2
- for comp3: comp3:$ export ROS_IP=11.22.33.3
3) Modify "/etc/hosts" file in order to resolve master's name to IP
- for comp2: comp2:$ sudo gedit /etc/hosts - add the following line to "hosts" in the format of "mastersIpAddress mastersName": 11.22.33.1 comp1 - save and close the file
- for comp3: SAME STEPS AS FOR comp2
Now everything should be set up but its good to test if it's actually working - Is ROS happy or not? For that you can use an example ROS nodes from rospy_tutorials package. If a particular machine does not have this package yet, then:
- install the tutorials package, don't forget to change the distro $ sudo apt-get install ros-<distro>-ros-tutorials
1) Run talker.py node on the master machine and leave it running
comp1:$ rosrun rospy_tutorials talker.py
2) Run listener.py node on the slaves computer and see if it receives the "hello" message:
comp2:$ rosrun rospy_tutorials listener.py
- for comp3: SAME STEPS AS FOR comp2
It might be a bit annoying to always set the slave up. For that you can create a script which includes all these commands. So in that case you can just source that file and things would be set up.
So for comp2
1) Create a text file however and where-ever you like, so in this example:
comp2:$ cd ~ comp2:~$ mkdir ros_master_config comp2:~$ cd ros_master_config comp2:~/ros_master_config$ nano comp1_as_master.bash
Now you have created and opened a new file called "comp1_as_master". Insert the commands that you need:
#!/usr/bin/env bash export ROS_MASTER_URI=http://11.22.33.1:11311 export ROS_IP=11.22.33.2 source ~/catkin_ws/devel/setup.bash
You don't need to source the setup.bash but it has to be done somewhere
- save and close the file
2) Source the file. Keep your current location in mind, so if you are in home folder, then
comp2:~$ source ros_master_config/comp1_as_master.bash
- Have you sourced the workspace?
- Can the machines ping each other?
- Are the machines in the same network/subnetwork?
- Do you have a correct hostname in /etc/hosts file? writing "hosts" in the terminal will show you the actual hostname.