22.ROS distributed communication

A running ROS system can contain multiple nodes distributed across multiple computers. Depending on the system configuration, any node may need to communicate with any other node at any time. However, a necessary condition for implementing this distributed communication is that each machine must be on the same local area network. In this lesson, we will use Raspberry Pi and Virtual Machine as an example to illustrate how to configure and implement distributed communication.

22.1 Preparation work

22.1.1 Configuration

Require:

22.1.2 Check ip address

Both are connected to the same LAN, query the network IP address through the following command,

Virtual machine side,

image-20231025115453254

The address found is 192.168.2.131

Raspberry Pi side,

image-20231025120113573

The found address is 192.168.2.117

22.2 Modify configuration file

22.2.1 Virtual machine side

Taking the virtual machine as a slave machine as an example, you need to modify the ROS_MASTER_URI of the virtual machine to the Raspberry Pi IP. Here is the 192.168.2.117 you just queried, enter it in the terminal,

After entering the password, add it at the bottom of the file,

image-20231025151710358

Exit after saving and reopen the terminal to refresh the environment variables to take effect.

Then, modify the/etc/hosts file,

image-20231025121908941

As shown in the picture above, add the Raspberry Pi's IP and machine name, save and exit.

22.2.2 Raspberry Pi terminal

The modified files and steps are almost the same as above. The only difference is that the ROS_MASTER_URI of the Raspberry Pi needs to be replaced with the local IP, which is 192.168.2.131. Just add the ip and machine name of the virtual machine at the end of the /etc/hosts file. The two files are as follows:

~/.bashrc

image-20231025151625167

/etc/hosts

image-20231025151544904

Similarly, exit after saving, reopen the terminal or source the terminal to refresh the environment variables.

22.3 Enable distributed communication

Let's verify whether the configuration is successful. First, on the host (here is the Raspberry Pi), start roscore and enter in the host terminal,

Then, run the little turtle node on the slave machine (virtual machine) and enter from the slave machine terminal,

A little turtle appears from the machine,

image-20231025152103076

Then, we start the little turtle keyboard control node on the host (Raspberry Pi), and input at the host terminal,

Click the keyboard to control the terminal, and then use the up, down, left and right buttons to control the movement of the little turtle on the virtual machine.

image-20231025152147175