pi-fastdds
把 FastDDS 封装成 Python 通信库,提供 publish/subscribe、RPC service、peer discovery 等原语。
特性
- 发布/订阅 — 基于 DDS topic 的单向数据流,支持 device 和 topic 两种地址模式
- RPC 服务 — 请求-响应模式,通过共享 topic 路由
- 远程参数 — 键值存储,复用 RPC 通道
- 节点发现 — 自动心跳,peer 上下线回调,RTT 测量(不依赖跨机时钟同步)
- 多实例隔离 — 每个
Comm独立DomainParticipant,不同domain_id严格隔离 - 跨平台分发 — FastDDS 静态链入 wheel,目标机无需预装 FastDDS
文档
| 文档 | 说明 |
|---|---|
| API 总览 | 快速开始、模块导出、核心概念 |
| C++ API | C++ 公共接口完整参考 |
| Python API | Python 接口完整参考,含示例 |
| 架构总览 | 技术栈、目录结构、模块划分、数据流 |
| 变更记录 | 版本历史 |
| 设计文档 v2 | 绑定设计 |
| Wheel 构建指南 | 构建与分发细节 |
快速开始
安装
# 从 wheel 安装(无需在目标机编译 FastDDS)
pip install wheelhouse/pi_fastdds-*.whl
最小示例
import time
import pi_fastdds as dds
# 创建两个通信节点
a = dds.Comm(device_name="node_a", device_id=1)
b = dds.Comm(device_name="node_b", device_id=2)
# 发布/订阅
received = []
addr = dds.Address.topic("telemetry")
sub = b.subscribe(addr, lambda msg: received.append(msg.payload))
time.sleep(0.3)
a.publish(addr, b"hello")
time.sleep(0.3)
print(f"收到: {received}") # [b'hello']
# 清理
sub.shutdown()
a.close()
b.close()
运行内置示例:
# 单机端到端示例(pub/sub + service + peer)
python examples/demo_python.py
# 上层插件 dogfood 示例
python examples/demo_uav_state.py
# 跨机端到端测试(需要两台机器)
# 在 server 机器:
python examples/demo_multihost.py server --id 1 --name node_a --domain 7
# 在 client 机器:
python examples/demo_multihost.py client --id 2 --target-id 1 --domain 7
编译指南
前置依赖
| 依赖 | 版本要求 | 说明 |
|---|---|---|
| C++ 编译器 | 支持 C++17 | GCC 9+ 或 Clang 10+ |
| CMake | 3.15+ | 构建系统 |
| Python | 3.8+ | 运行时 |
| ninja | 任意 | 构建加速(可选但推荐) |
| auditwheel | 任意 | wheel 修复(pip install auditwheel) |
步骤 1:编译 FastDDS 静态库
FastDDS 以源码形式 vendored 在 thirdparty/fastdds/,需要编译为静态库。
cd thirdparty/fastdds
bash build_static.sh
这会编译 foonathan_memory、fastcdr、fastdds 三个库,安装到 thirdparty/fastdds/install/。
关键编译选项(已在脚本中设置):
-DCMAKE_POSITION_INDEPENDENT_CODE=ON— 必须,否则链接 .so 时会报recompile with -fPIC-DBUILD_SHARED_LIBS=OFF— 静态库-DCMAKE_BUILD_TYPE=Release— 默认 Release
编译产物:
thirdparty/fastdds/install/
├── include/ # 头文件
└── lib/
├── libfastdds.a
├── libfastcdr.a
└── libfoonathan_memory-0.7.4.a
步骤 2:编译 Python wheel
# 安装构建工具
pip install scikit-build-core auditwheel patchelf ninja
# 运行构建脚本
bash scripts/build_wheel.sh
脚本会:
- 用
pip wheel编译初始 wheel(linux_x86_64标签) - 用
auditwheel repair修复为manylinux标签,打包系统库(libssl/libcrypto/libtinyxml2)
产物:
dist/ # 初始 wheel(linux_x86_64)
wheelhouse/ # 修复后的 manylinux wheel(可分发)
指定 Python 版本
默认使用 python3.10。指定其他版本:
# Python 3.8
PYTHON=python3.8 bash scripts/build_wheel.sh
Python 3.8 会使用 thirdparty/nanobind-py38/(v2.9.x),Python 3.10+ 使用 thirdparty/nanobind/(最新版)。
批量编译(conda)
用 conda 自动创建不同 Python 版本的独立环境,批量编译 wheel:
# 全部编译(3.9 / 3.10 / 3.11 / 3.12)
bash scripts/build_wheels_conda.sh
# 指定版本
bash scripts/build_wheels_conda.sh 3.9 3.11
效果:
| wheel | Python |
|---|---|
pi_fastdds-*-cp39-cp39-manylinux_2_31_x86_64.whl |
3.9 |
pi_fastdds-*-cp310-cp310-manylinux_2_31_x86_64.whl |
3.10 |
pi_fastdds-*-cp311-cp311-manylinux_2_31_x86_64.whl |
3.11 |
pi_fastdds-*-cp312-cp312-manylinux_2_31_x86_64.whl |
3.12 |
首次运行会创建 conda 环境,后续复用已存在的环境,只重新编译 wheel。
glibc 说明:本机编译 + auditwheel 产出
manylinux_2_31标签的 wheel, 要求目标系统 glibc ≥ 2.31(Ubuntu 20.04+、Debian 11+)。 如需支持更旧的 glibc(如 CentOS 7,glibc 2.17),需在对应 manylinux Docker 镜像中 同时重建 FastDDS 静态库和 Python wheel,参考scripts/build_wheels_batch.sh(Docker 方案)。
测试
# 安装 pytest
pip install pytest
# 运行完整测试套件
python -m pytest tests/ -v
# 运行特定测试
python -m pytest tests/test_pubsub.py -v
python -m pytest tests/test_service.py -v
python -m pytest tests/test_peer.py -v
测试覆盖:
test_address.py— Address 工厂与校验test_pubsub.py— 发布/订阅基本功能、队列、回调串行化、关闭语义test_service.py— RPC 服务调用、超时、异常处理test_peer.py— 节点发现、上下线回调、心跳配置test_param.py— 远程参数读写test_exceptions.py— 异常体系
下载源码
git clone git@gitee.com:pi-lab/pi-fastdds.git
目录结构
pi-fastdds/
├── cxx/ # C++ 核心库
│ ├── pi_fastdds/
│ │ ├── include/pi_fastdds/ # 公共头文件
│ │ └── src/ # 实现 + Python 绑定
│ └── dds_comm/fastdds/ # IDL 生成代码
├── python/pi_fastdds/ # Python 包
├── examples/ # 示例程序
├── tests/ # pytest 测试
├── thirdparty/ # vendored 依赖
│ ├── fastdds/ # FastDDS 源码 + 构建脚本
│ ├── nanobind/ # nanobind(Python 3.10+)
│ └── nanobind-py38/ # nanobind v2.9.x(Python 3.8)
├── wheelhouse/ # 构建好的 wheel
├── scripts/build_wheel.sh # wheel 构建脚本
├── docs/ # 文档
└── pyproject.toml # Python 包配置
许可证
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pi_fastdds-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: pi_fastdds-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe739c055185471e0f819b23fa08909d8957037fcdd5d4d17ca23cd09648dd78
|
|
| MD5 |
1e0335acdcecef92510a3d6bf72c0988
|
|
| BLAKE2b-256 |
bf74da77a5243ad4a0175dc41b1b0a44c626505144240a38b04fab2a034bcef9
|
File details
Details for the file pi_fastdds-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: pi_fastdds-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e09e689d7ecbc10f50dff5e1722f36b9ed5ad2d21680c9831e7ce0a4ff71433
|
|
| MD5 |
3706e40abcf205ecda9c8127a6c4e8d8
|
|
| BLAKE2b-256 |
849bdebe0787d2eb1b684c280f7ef574fe0d01b3a98286768fc1c1e6302dd7e0
|
File details
Details for the file pi_fastdds-0.1.2-cp310-cp310-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: pi_fastdds-0.1.2-cp310-cp310-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b66a23b3a4b217fb14e812bac80a30ed539b1b088385a17df7268f3a4e193de
|
|
| MD5 |
e94e53d55d80b1808b27483981268dbe
|
|
| BLAKE2b-256 |
2d3189bb3be28fdd01bb74edac58cb78c821573743cd71f71fb3f7fd45393e02
|
File details
Details for the file pi_fastdds-0.1.2-cp39-cp39-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: pi_fastdds-0.1.2-cp39-cp39-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59d99f39d84064bbdc2bcaee336ddcb96733866234863feb1f7a0b0e3a0c2bef
|
|
| MD5 |
06350a4b61510b89ed2ee44b01d8b880
|
|
| BLAKE2b-256 |
9d103919019c6120a53ca7649bda16817c7e7314b2313b2ca738d07b030dd335
|