04. Multi-computer communication configuration4.1. Concepts4.2 Implementation4.2.1 Default implementation4.2.2. Distributed network grouping4.3 Notes4.4 Calculation rules for DDS domain ID values
The operating environment and hardware and software reference configuration are as follows:
Multi-computer communication, i.e. distributed communication, is a communication strategy that allows data interaction between different hosts over a network.
ROS2 itself is a distributed communication framework, which can easily realize the communication between different devices. The middleware that ROS2 is based on is DDS, and when in the same network, distributed communication can be realized through the domain ID mechanism (ROS_DOMAIN_ID) of DDS, and the general process is: before starting a node, you can set the value of the domain ID, and different nodes can freely discover and communicate with each other if they have the same domain ID. are the same, then they can freely discover and communicate, and vice versa, if the domain ID values are different, it cannot be realized. By default, the domain ID used for all nodes to start up is 0. In other words, as long as you ensure that you are on the same network, you don't need to do any configuration for different nodes on different ROS2 devices to realize distributed communication.
Distributed communication is used in a wide range of scenarios, such as unmanned vehicle formations, drone formations, remote control, and so on, all of which rely on distributed communication for data interaction.
Distributed communication is already realized by simply having the host and the slave [there can be more than one] in the same network. For example, the host and the slave are connected to the same WiFi or the same router.
The virtual machine in Windows is in the same network as the host by setting the network to [bridge mode].
Test:
1, the host side of the [cart] execution:
Demonstration here is the cart in docker, docker uses the network mode is host mode, host mode is simply and the cart share a network, so with the cart on the implementation of no difference.
xxxxxxxxxx
ros2 run demo_nodes_py talker
xxxxxxxxxx
ros2 run demo_nodes_py listener
If the following is displayed: the topic published by the host can be subscribed to by the slave in time, it means that multi-computer communication has been realized
Assuming that there are other robots in use in the network you are in now, in order not to be interfered by other robots, you can also set up a grouping for your robots.
ROS2 provides a DOMAIN mechanism, similar to grouping, in the same DOMAIN in the computer to communicate, we can be in the host side of the [trolley] and the slave side of the [virtual machine] of the .bashrc to add such a sentence in the configuration, you can assign the two to a group:
xxxxxxxxxx
$ export ROS_DOMAIN_ID=<your_domain_id>
If the IDs assigned to the host side [cart] and the slave side [VM] are different, the two cannot communicate for the purpose of grouping.
Test:
1, the host side [cart] execution:
Demonstrated here is the cart is in docker, docker uses the network mode is host mode, host mode is simply and the cart share a network, so with the cart on the implementation of no difference.
xxxxxxxxxx
echo "export ROS_DOMAIN_ID=6" >> ~/.bashrc # 这里的6是ROS_DOMAIN_ID, 不一定要用6,符合ROS_DOMAIN_ID的规则即可
# The 6 here is the ROS_DOMAIN_ID, it doesn't have to be a 6, just the ROS_DOMAIN_ID rule.
source ~/.bashrc
ros2 run demo_nodes_py talker
xxxxxxxxxx
echo "export ROS_DOMAIN_ID=6" >> ~/.bashrc # 这里和主机端的值保持一致
# It's consistent with the values on the host side
source ~/.bashrc
ros2 run demo_nodes_py listener
If the following is displayed: the topic posted by the host can be subscribed to by the slave in time, it means that grouped multi-computer communication has been realized
The value of ROS_DOMAIN_ID is not arbitrary, there are some constraints:
The rules related to the calculation of the domain ID value are as follows:
The above calculation rules can be understood.