用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill ros2-distributed-communication命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | ros2-distributed-communication |
| description | ROS2 分布式通讯技能 - DDS/RMW 配置、多机器通讯、网络优化、跨域配置 |
| user-invocable | true |
| argument-hint | 分布式通讯 OR dds OR rmw OR 多机器 OR 跨域 OR network |
ROS2 DDS/RMW 分布式通讯完整指南
当需要以下帮助时使用此技能:
| 实现 | 包 | 特性 |
|---|---|---|
| CycloneDDS | rclcpp | 高性能,默认 |
| FastRTPS | fastrtps | 低延迟 |
| Connext | rti-connext | 企业级(收费) |
┌─────────────┐ ┌─────────────┐
│ Node A │ │ Node B │
│ (机器 A) │ │ (机器 B) │
└──────┬──────┘ └──────┬──────┘
│ │
└────────┬──────────┘
│
┌──────┴──────┐
│ RMW │
│ (DDS层) │
└──────┬──────┘
│
┌──────┴──────┐
│ Network │
│ (UDP/TCP) │
└─────────────┘
# 使用 FastRTPS
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
# 使用 CycloneDDS
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
# 使用 Connext (如已安装)
export RMW_IMPLEMENTATION=rmw_connext_cpp
# 验证
ros2 doctor -r
// 代码中切换
rclcpp::init(argc, argv,
rclcpp::InitOptions::from_raw_arguments(
"--rmw", "rmw_fastrtps_cpp"));
<!-- fastrtps.xml -->
<?xml version="1.0" ?>
<profiles>
<participant name="participant_name">
<rtps>
<discoveryProtocol>SIMPLE</discoveryProtocol>
<discoveryServers>
<RemoteServer prefix="uuid">
<metatrafficUnicastLocatorList>
<locator>
<udpv4>
<address>192.168.1.100</address>
<port>11811</port>
</udpv4>
</locator>
</metatrafficUnicastLocatorList>
</RemoteServer>
</discoveryServers>
</rtps>
</participant>
</profiles>
# 机器 A (服务器)
export ROS_LOCALHOST_ONLY=0
export RMW_FASTRTPS_DEFAULT_PROFILES_FILE=/path/to/fastrtps.xml
export FASTRTPS_DEFAULT_PROFILE=file:///path/to/fastrtps.xml
# 或者使用域 ID
export ROS_DOMAIN_ID=42
# 机器 A
ros2 run demo_nodes_cpp listener
# 机器 B
ros2 run demo_nodes_cpp talker
# 查看话题
ros2 topic list
// 高可靠性配置
rclcpp::QoS reliable_qos(10);
reliable_qos.reliability(RMW_QOS_POLICY_RELIABILITY_RELIABLE)
.durability(RMW_QOS_POLICY_DURABILITY_VOLATILE);
auto sub = node->create_subscription<MyMsg>(
"/topic", reliable_qos, callback);
<!-- 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="0">
<discovery>
<ParticipantIndex>auto</ParticipantIndex>
<MaxAutoParticipantIndex>50</MaxAutoParticipantIndex>
</discovery>
<internal>
<NetworkInterfaceAddress>auto</NetworkInterfaceAddress>
</internal>
</domain>
<domain id="1">
<discovery>
<ParticipantIndex>auto</ParticipantIndex>
</discovery>
</domain>
</cyclonedds>
<!-- 指定网络接口 -->
<profiles>
<participant name="participant_name">
<rtps>
<transport>
<sendSocketBufferSize>
<size>1048576</size>
</sendSocketBufferSize>
<receiveSocketBufferSize>
<size>1048576</size>
</receiveSocketBufferSize>
</transport>
<metatrafficUnicastLocatorList>
<locator>
<udpv4>
<address>192.168.1.10</address>
<port>7400</port>
</udpv4>
</locator>
</metatrafficUnicastLocatorList>
</rtps>
</participant>
</profiles>
// 增加队列深度处理高吞吐
rclcpp::QoS high_throughput_qos(100); // 深度100
high_throughput_qos.best_effort()
.durability_volatile();
auto pub = node->create_publisher<sensor_msgs::msg::PointCloud2>(
"/points", high_throughput_qos);
# 使用不同域隔离通讯
export ROS_DOMAIN_ID=0 # 主系统
export ROS_DOMAIN_ID=1 # 测试系统
export ROS_DOMAIN_ID=2 # 开发系统
<!-- 只订阅特定域的数据 -->
<dataReader name="my_reader">
<topic>
<name>robot/chassis</name>
<dataType>MyType</dataType>
<domainId>0</domainId>
</topic>
</dataReader>
# 检查网络
ping other_machine
# 检查域 ID
echo $ROS_DOMAIN_ID
# 查看 ROS 诊断
ros2 doctor
# 列出所有节点
ros2 node list
# 查看节点信息
ros2 node info /talker
# 检查话题列表
ros2 topic list
# 查看话题类型
ros2 topic type /chatter
# 手动发布测试
ros2 topic pub /chatter std_msgs/msg/String "data: test"
# 查看实时数据
ros2 topic echo /chatter
# 诊断工具
ros2 daemon start
ros2 doctor --report
# 查看当前 RMW
ros2 pkg list | grep rmw
# 查看话题通讯
ros2 topic hz /chatter
ros2 topic bw /chatter
# 网络诊断
ros2 network_scanner
# 启用日志调试
export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message}"
export RCUTILS_LOGGING_BUFFER_OUTPUT_STRING=0
# RMW 调试
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILE=file://fastrtps_debug.xml