Python Behavior Tree Framework with C++ Core
Project description
PSBTree 行为树引擎
基于 C++ 和 Python 实现的高性能行为树引擎,支持顺序和并行执行模式,适用于机器人控制、游戏 AI 和自动化系统。
项目结构
.
├── src/ # 源代码目录
│ └── psbtree/ # 主包目录
│ ├── engine/ # 引擎实现(顺序和并行)
│ ├── nodes/ # 节点实现(动作、条件、控制、装饰器)
│ ├── plugins/ # 插件系统
│ └── utils/ # 工具函数
├── sample/ # 示例代码
├── tests/ # 测试代码
├── doc/ # 文档
├── source_cpp/ # C++ 源代码
├── dependencies/ # 依赖项
├── scripts/ # 构建脚本
├── pyproject.toml # 项目配置
├── setup.py # 安装脚本
└── README.md # 项目文档
核心功能
- 行为树引擎: 支持顺序和并行执行模式
- 节点系统: 提供丰富的节点类型(动作、条件、控制、装饰器)
- 高性能: 核心功能使用 C++ 实现,通过 Cython 与 Python 集成
- 授权系统: 内置授权验证机制
- 插件扩展: 支持通过插件系统扩展功能
快速开始
-
安装依赖:
pip install -r requirements.txt
-
安装包:
pip install .
-
设置授权码:
from psbtree import set_sk_code set_sk_code("您的授权码")
-
运行示例:
python sample/sequential_engine_sample.py
依赖管理
核心依赖包括:
loguru: 日志记录psdec: 授权验证opencv-python: 图像处理(示例中使用)
使用示例
顺序引擎示例
from psbtree.engine.sequential_engine import SequentialEngine
from psbtree.nodes import SimpleActionNode, TreeNode, NodeStatus
from psbtree import set_sk_code
# 设置授权码
set_sk_code("您的授权码")
# 创建顺序引擎
engine = SequentialEngine()
# 注册节点
engine.register_action_class(YourActionNode, "YourActionNode")
# 定义行为树XML
xml_text = """
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<YourActionNode />
</Sequence>
</BehaviorTree>
</root>
"""
# 从XML创建行为树
engine.create_tree_from_text(xml_text)
# 运行行为树
status = engine.tick_once()
并行引擎示例
from psbtree.engine.parallel_engine import ParallelEngine
from psbtree.nodes import SimpleActionNode, TreeNode, NodeStatus
from psbtree import set_sk_code
# 设置授权码
set_sk_code("您的授权码")
# 创建并行引擎
engine = ParallelEngine()
# 注册节点
engine.register_action_class(YourActionNode, "YourActionNode")
# 定义多个行为树XML
xml_text_tree0 = """
<root BTCPP_format="4">
<BehaviorTree ID="Tree0">
<Sequence name="root_sequence">
<YourActionNode />
</Sequence>
</BehaviorTree>
</root>
"""
# 从XML创建行为树
tree_id0 = engine.create_tree_from_text(xml_text_tree0, "tree0")
# 运行行为树
status0 = engine.tick_once(tree_id0)
开发指南
- 使用
SimpleActionNode作为基类创建自定义节点 - 通过
ports静态变量定义节点的输入输出端口 - 实现
tick静态方法定义节点的行为 - 使用 XML 格式定义行为树结构
- 遵循行为树设计模式最佳实践
贡献
欢迎提交 PR 和 issue。请确保:
- 代码符合项目编码规范
- 包含必要的单元测试
- 更新相关文档
许可证
MIT License
Project details
Release history Release notifications | RSS feed
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 psbtree-0.1.21-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: psbtree-0.1.21-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc2c12d114e0473fdab70316a172cda6a75887424b215fd44570aa08629205a5
|
|
| MD5 |
9702a5d8c3eaa2fdc4aa47e035a7d586
|
|
| BLAKE2b-256 |
a60f9dee41763a42a3319933292bf8fce67a8d07b9c080e9e8f1f808d4d0e809
|
File details
Details for the file psbtree-0.1.21-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: psbtree-0.1.21-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b539289afd4815962b8e4d3a8cfa7df55dbde5df2a5b1d388412c30223cf15a1
|
|
| MD5 |
a02abc6af3b321aa4ae65daa87d09fe8
|
|
| BLAKE2b-256 |
e4f04791453d8c0bdd3e112d2413705179290da73595f4a99c70b0c15678a1ca
|
File details
Details for the file psbtree-0.1.21-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: psbtree-0.1.21-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832706f16c9d0110ef5e5a717f3af799227165443c30eebb955fa3bb0bc3130d
|
|
| MD5 |
b051d6de00883c06c93cca3417594d73
|
|
| BLAKE2b-256 |
82f919cb978194888d9b5d227da2b77c29f8e4aa85926c398c897fe9835e17c4
|
File details
Details for the file psbtree-0.1.21-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: psbtree-0.1.21-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9daccee185fbad34771b3f3f1bbb8df4541f68b115e21cf82289deb595574238
|
|
| MD5 |
0cd6a667910314c50a3481a37aa9d763
|
|
| BLAKE2b-256 |
620d7e57cb40a76ffd3f96b12a57a2431bfe1f69a0175f4c605e01117ba90ad5
|
File details
Details for the file psbtree-0.1.21-cp39-cp39-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: psbtree-0.1.21-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
663f49b57aa03d9babe9d5305899123a4ea2b7620f891893054c93b1e0803e9a
|
|
| MD5 |
c2ee7a3f5c4931621fb4976380ec8b13
|
|
| BLAKE2b-256 |
d589a7a850195fe2727856fe6cd54ade7ea6b45d9921a236f313eeb77b5ce0a5
|