Modify ROS_DOMAIN_ID on multiple machines

(Must read if there are multiple machines in the same LAN!!!)

Assuming that there are other machines in use in your current network, you can also set up a group for your machine in order to avoid interference from other machines.

ROS2 provides a DOMAIN mechanism, just like grouping, only computers in the same DOMAIN can communicate. We can add such a configuration in .bashrc to assign the two to a group:

image-20250408192203556

In order to use the ros2 environment in Jupyter Lab, we need to modify the Jupyter Lab self-starting script, so that every time the Jupyter Lab service is started, the ros environment of the Jupyter Lab service will be under the domainid.

image-20250408192621141

Note

When setting the value of ROS_DOMAIN_ID, it is not arbitrary, but also has certain constraints:

  1. It is recommended that the value of ROS_DOMAIN_ID be between [0,101], including 0 and 101;

  2. The total number of nodes in each domain ID is limited and needs to be less than or equal to 120;

  3. If the domain ID is 101, the total number of nodes in the domain needs to be less than or equal to 54.

Calculation rules for DDS domain ID values

The calculation rules for domain ID values ​​are as follows:

  1. DDS is based on TCP/IP or UDP/IP network communication protocols. When communicating over the network, you need to specify a port number, which is represented by a 2-byte unsigned integer and has a value range of [0,65535];

  2. The allocation of port numbers also has its rules and cannot be used arbitrarily. According to the DDS protocol, 7400 is used as the starting port, which means that the available ports are [7400,65535]. It is also known that according to the default DDS protocol, each domain ID occupies 250 ports, so the number of domain IDs is: (65535-7400)/250 = 232 (numbers), and the corresponding value range is [0,231];

  3. The operating system will also set some reserved ports. When using ports in DDS, you need to avoid these reserved ports to avoid conflicts during use. Different operating systems have different reserved ports. The final result is that under Linux, the available domain IDs are [0,101] and [215-231], and the available domain IDs in Windows and Mac are [0,166]. In summary, in order to be compatible with multiple platforms, it is recommended that the domain ID be in the range of [0,101].

  4. Each domain ID occupies 250 ports by default, and each ROS2 node needs to occupy two ports. In addition, according to the DDS protocol, in the port segment of each domain ID, the 1st and 2nd ports are the Discovery Multicast port and the User Multicast port. Starting from the 11th and 12th ports, they are the Discovery Unicast port and the User Unicast port of the first node in the domain. The ports occupied by subsequent nodes are extended in sequence. Then the maximum number of nodes in a domain ID is: (250-10)/2 = 120 (nodes);

  5. Special case: When the domain ID value is 101, the second half of the ports belong to the reserved ports of the operating system, and the maximum number of nodes is 54.

The above calculation rules can be understood.