Welcome to ROSMASTER X3 repository
4. Multi-machine communication configuration
4. Multi-machine communication configuration
4. Multi-machine communication configuration 4.1. concept 4.2. achieve4.2.1. Default implementation4.2.2. Distributed network packet4.3. Attention4.4. DDS Rules for calculating domain ids
Note: Before logging in remotely, you must know the IP of the robot, which can be displayed on an external monitor or OLED.
For example, the following figure: Username [jetson], hostname [yahboom].

The operating environment and software and hardware reference configurations are as follows:
Reference model:ROSMASTER X3
Robot hardware configuration: Arm series master, Slan A1 LiDAR, AstraPro Plus depth camera
Robot system: Ubuntu (version not required) + docker (version 20.10.21 and above)
PC VM: Ubuntu (20.04) + ROS2 (Foxy)
Usage scenario: Used on a relatively clean 2D plane
4.1. concept
Multi-computer communication, or distributed communication, is a communication strategy that can realize data interaction between different hosts through the network.
ROS2 itself is a distributed communication framework, which can conveniently realize the communication between different devices. The middleware based on ROS2 is DDS. When in the same network, distributed communication can be realized through the ROS DOMAIN ID mechanism of DDS. The general process is as follows: Before starting the node, you can set the value of the domain ID. If the domain ID of different nodes is the same, they can discover and communicate freely. Otherwise, if the domain ID value is different, it cannot be realized. By default, all nodes are started with a domain ID of 0, in other words, as long as you ensure that you are on the same network, you do not need to do any configuration, different nodes on different ROS2 devices can achieve distributed communication.
The application scenarios of distributed communication are more extensive, such as unmanned vehicle formation, drone formation, remote control, etc. The interaction of these data all rely on distributed communication.
4.2. achieve
4.2.1. Default implementation
You only need to put the host and slave (can have multiple)in the same network, you have achieved distributed communication. For example, the host and slave are connected to the same WiFi or the same router.
In Windows, if the network of the VM is set to Bridge mode, the VM and the host are on the same network
TEST:
Host side [robot] execution:
What is demonstrated here is that the robot is in docker, and the network mode used by docker is host mode, which simply means that the host mode shares a network with the robot, so it is no different from the execution on the robot.
ros2 run demo_nodes_py talker
This command is executed [secondary VM]:
xxxxxxxxxxros2 run demo_nodes_py listener
If the following information is displayed: A topic published on the host can be subscribed to from the host in time, multi-host communication has been implemented

4.2.2. Distributed network packet
If you are in a network with other robots in use, you can also set up a group for your robots in order not to be disturbed by other robots.
ROS2 provides a DOMAIN mechanism, just like grouping, computers in the same DOMAIN can communicate. We can add such a configuration in the .bashrc of the host side [robot] and the slave side [VM] to assign the two to a group:
xxxxxxxxxx$ export ROS_DOMAIN_ID=<your_domain_id>
If the ID assigned by the host [car] and the slave [virtual machine] is different, the two cannot communicate and achieve the purpose of grouping.
TEST:
Host side [robot] execution:
What is demonstrated here is that the robot is in docker, and the network mode used by docker is host mode, which simply means that the host mode shares a network with the robot, so it is no different from the execution on the robot.
xxxxxxxxxxros2 run demo_nodes_py talker
This command is executed [secondary VM]:
xxxxxxxxxxros2 run demo_nodes_py listener
If the following information is displayed: A topic published on the host can be subscribed to from the host in time, multi-host communication has been implemented

4.3. Attention
Setting the ROS DOMAIN ID value is not arbitrary, and there are certain constraints:
It is recommended that the ROS DOMAIN ID be between 0 and 101, including 0 and 101.
The total number of nodes in each domain ID is limited and must be less than or equal to 120.
If the domain ID is 101, the total number of nodes in the domain must be less than or equal to 54.
4.4. DDS Rules for calculating domain ids
The rules for calculating domain ID values are as follows:
DDS is based on the TCP/IP or UDP/IP network communication protocol. During network communication, you need to specify a port number. The port number is represented by an unsigned integer of 2 bytes, whose value ranges from 0 to 65535.
Port number allocation also has its rules, not can be used arbitrarily, according to the DDS protocol to 7400 as the starting port, you can also use the port is [7400,65535], and it is known that according to the DDS protocol by default, each domain ID occupies 250 ports, then the number of domain ids is: (65,535-7400)/250 = 232(each), the corresponding value range is [0,231].
The operating system also sets some reserved ports, and when using ports in DDS, you need to avoid these reserved ports, so as to avoid conflicts in use. Different operating systems have different reserved ports, and the final result is that under Linux, the available domain ids are [0,101] and [215-231]. The available domain ID on Windows and Mac is [0,166]. To be compatible with multiple platforms, it is recommended that the domain ID be in the range of [0,101].
By default, each domain ID occupies 250 ports, and each ROS2 node needs to occupy two ports. In addition, according to the DDS protocol, the first and second ports in the port segment of each domain ID are Discovery Multicast ports and User Multicast ports. Start with ports 11 and 12, which is the first node Discovery Unicast port and User Unicast port, Ports occupied by subsequent nodes are extended successively. The maximum number of nodes in a domain ID is : (250-10)/2 = 120.
Special case: If the domain ID is 101, the latter half of the domain port is reserved for the operating system, and the maximum number of nodes is 54.
Notes : The above calculation rules can be just simple understood.