This manual explains the process for connecting ROS Nodes on multiple machines connected to the same network.
| Hostname | comp1 | comp2 |
|---|---|---|
| IP | 192.168.77.11 | 192.168.77.12 |
-
Configuring ROS master: There should be only a single master/ROS core for handling the system. In this example, let the comp1 be the master. Hence,
roscoreis run on this computer.comp1: $ roscore -
This should start the
roscoredisplaying the master's IP address and the port number.11311is the default port of the master. -
Configuring Slaves:
-
The slave machines need to know the master's as well as their own IP address.
-
comp1 can act as a slave to itself along with being the master.
Specify ROS master's IP:
comp1: $ export ROS_MASTER_URI=http://192.168.77.11:11311Specify slave machine's own IP:
comp1: $ export ROS_IP=192.168.77.11 -
comp2 will only act as a slave machine.
Specify ROS master's IP:
comp2 : export ROS_MASTER_URI=http://192.168.77.11:11311Specify slave machine's own IP:
comp2 : $ export ROS_IP=192.168.77.12
Note: In case of more number of machines, one of them can solely act as the master with the
roscorerunning on it and all other nodes running on the slaves. -
-
Resolve master's name to IP (Optional):
Modify the
/etc/hostsfile in order to resolve master's name to IP in the slave machine.-
In the slave machine, comp2, open the file as
Rootuser:comp2 : $ sudo nano /etc/hosts -
Add the line to the
hostsfile in the format of:<Master's IP Address> <Master's Name>
For example,
192.168.77.11 comp1
-
Save and close the file.
-
Note: The commands for specifying the IP address of ROS master and the slave can also be added to a bash file and sourced when required instead of typing it every time.
Robotics System Toolbox enables one to interface with ROS and use ROS functionality in MATLAB and Simulink. One can connect to a ROS network, collect data, send and receive one's own messages, and deploy code to a standalone system.
-
Configuring ROS Master:
-
To initialize ROS master using MATLAB-ROS, run the following command in the MATLAB Command Window:
For comp1,
>> rosinit -
This should start the
roscoreand display the IP address of ROS master and the port numbers of ROS Master and the global node on the command window.
Note: For running a ROS node in the master, the MATLAB code just needs to be run. No separate configurations are required.
-
-
Configuring Slaves:
-
Before running the slave nodes, MATLAB-ROS must be initialized with a master in the network. To do so, the IP address of the ROS master must be passed as an argument to the
rosinitfunction.Eg:
rosinit('<Master's IP Address>')For comp2,
>> rosinit('192.168.77.11')
-
Note: In case of one of the computer with MATLAB-ROS and other with On-Board ROS, the nodes can communicate over the network using the corresponding configurations.