ROS 2 和 Autoware 的 DDS 设置#
启用仅限 localhost 的通信#
- 为
lo启用multicast - 确保
export ROS_LOCALHOST_ONLY=1不存在 在.bashrc中.- 有关更多信息,请参阅 关于
ROS_LOCALHOST_ONLY环境变量.
- 有关更多信息,请参阅 关于
优化 DDS 设置#
Autoware 使用 DDS 进行节点间通信.ROS 2 文档 建议用户调整 DDS 以利用其功能.
注意
CycloneDDS 是 Autoware 的推荐且经过最多测试的 DDS 实施.
警告
如果不调整这些设置,Autoware 将无法接收点云或图像等大型数据.
调整系统范围的网络设置#
在启动 Autoware 之前,设置配置文件路径并放大 Linux 内核最大缓冲区大小.
# Increase the maximum receive buffer size for network packets
sudo sysctl -w net.core.rmem_max=2147483647 # 2 GiB, default is 208 KiB
# IP fragmentation settings
sudo sysctl -w net.ipv4.ipfrag_time=3 # in seconds, default is 30 s
sudo sysctl -w net.ipv4.ipfrag_high_thresh=134217728 # 128 MiB, default is 256 KiB
要使其永久,
sudo nano /etc/sysctl.d/10-cyclone-max.conf
将以下内容粘贴到文件中:
# Increase the maximum receive buffer size for network packets
net.core.rmem_max=2147483647 # 2 GiB, default is 208 KiB
# IP fragmentation settings
net.ipv4.ipfrag_time=3 # in seconds, default is 30 s
net.ipv4.ipfrag_high_thresh=134217728 # 128 MiB, default is 256 KiB
这里每个参数的详细信息在 ROS 2 文档 中进行了解释.
验证 sysctl 设置#
user@pc$ sysctl net.core.rmem_max net.ipv4.ipfrag_time net.ipv4.ipfrag_high_thresh
net.core.rmem_max = 2147483647
net.ipv4.ipfrag_time = 3
net.ipv4.ipfrag_high_thresh = 134217728
CycloneDDS 配置#
将以下文件另存为 ~/cyclonedds.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
<Domain Id="any">
<General>
<Interfaces>
<NetworkInterface autodetermine="false" name="lo" priority="default" multicast="default" />
</Interfaces>
<AllowMulticast>default</AllowMulticast>
<MaxMessageSize>65500B</MaxMessageSize>
</General>
<Internal>
<SocketReceiveBufferSize min="10MB"/>
<Watermarks>
<WhcHigh>500kB</WhcHigh>
</Watermarks>
</Internal>
</Domain>
</CycloneDDS>
然后将以下行添加到您的 ~/.bashrc 文件中.
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=file:///absolute/path/to/cyclonedds.xml
# Replace `/absolute/path/to/cyclonedds.xml` with the actual path to the file.
# Example: export CYCLONEDDS_URI=file:///home/user/cyclonedds.xml
有关更多详细信息,请参阅 Eclipse Cyclone DDS:运行时配置文档.
其他信息:#
关于 ROS_LOCALHOST_ONLY 环境变量#
以前,我们过去常常设置 export ROS_LOCALHOST_ONLY=1 来启用仅限 localhost 的通信.
但是由于 一个持续的问题,这种方法不起作用.
警告
不要在 ~/.bashrc 中设置 export ROS_LOCALHOST_ONLY=1.
如果这样做,将导致 RMW 出错.
如果你已经设置了它,请从 ~/.bashrc 中删除它.
关于 ROS_DOMAIN_ID 环境变量#
我们还可以设置 export ROS_DOMAIN_ID=3(或任何数字 1 到 255)(默认为 0),以避免干扰同一网络上的其他 ROS 2 节点.
但是,由于 255 是一个非常小的数字,除非您确保每个人都具有唯一的域 ID,否则它可能会干扰同一网络上的其他计算机.
另一个问题是,如果有人运行使用 ROS 2 launch_testing 框架的测试, 默认情况下,它将使用随机域 ID 来隔离测试,即使在同一台计算机上也是如此. 有关详细信息,请参阅 此 PR.