Skip to main content

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 集成
  • 授权系统: 内置授权验证机制
  • 插件扩展: 支持通过插件系统扩展功能

快速开始

  1. 安装依赖:

    pip install -r requirements.txt
    
  2. 安装包:

    pip install .
    
  3. 设置授权码:

    from psbtree import set_sk_code
    set_sk_code("您的授权码")
    
  4. 运行示例:

    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

psbtree-0.1.7-cp313-cp313-manylinux_2_28_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

psbtree-0.1.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

psbtree-0.1.7-cp312-cp312-manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

psbtree-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

psbtree-0.1.7-cp311-cp311-manylinux_2_28_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

psbtree-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

psbtree-0.1.7-cp310-cp310-manylinux_2_28_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

psbtree-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

psbtree-0.1.7-cp39-cp39-manylinux_2_28_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

psbtree-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file psbtree-0.1.7-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6368824ce4019ff19a19dd0d2748deecb87af6c65b22536f629f30c83d739a10
MD5 44774aab7daa4f284a317344e834b23c
BLAKE2b-256 329e12ad5c03a7dd4e29e69a0fdc9edab385d11aaa246df3a70939687e77074a

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd5a1b0dc61dd600b66d658cce9fbdc84d706b4bca318302ef8730b9e6aced9d
MD5 e6c5a24bd1914a638d3439daa177678f
BLAKE2b-256 bce4db9def053457798fc8827f2b1a07260e4e34ef33b00de6a02917a57c8c88

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a2b07d6882dd5fcf38059868ab29d9da4b1deb7f0ebceaea5313c8ad801571b4
MD5 9f83b075a3a8447899edd1ea9d3449ad
BLAKE2b-256 aa29a700d46f5d0c9598fd50711cf61cc2c912f9a3beca8f0086f6b51ac0cff3

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86529510e2be44cb6a6b5c5f1a976bd2acbb40e686b00c09abfce3246ef2ea69
MD5 5499ed1a5546ea4f553769d0194a0757
BLAKE2b-256 98956a03089735de6216b79f80c75ededc6559741f0806c9be13d031ebc1da1f

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03d32ff52ceee84455fe67dd52ea2c23ff1c6baedf39f3d874e137441328987a
MD5 84820a63ebfd6d969a5c5e035519c021
BLAKE2b-256 df1afce6d9cdfd870fc98c585167b4be7b61ec09e50b4b4e6f8f6aee7b578826

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b718d49af01df6263538a7bed940d4abd122fa160a484f927b1413ed12cf90b
MD5 8d03d049e44d030adcef37335fdaacca
BLAKE2b-256 2c2f7def568e0178fa8e1ea339aa7da78384a745c06a93b9bb69156403700e38

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee2e4ceef85a4cf1404518e0d6cb060a944165a111fc1f624259e8dae5594f9e
MD5 0aacc23af71ab658114682528a7b7382
BLAKE2b-256 260307788c832e43d3ca6092d8d339058a90d1c713028756867e7443454d4eb7

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4667b2c3d1fca7a440730ea313c6e1379298f43795dd7957523752f995e9c0f1
MD5 166a0351f70c5681c443ec7bcf611ee0
BLAKE2b-256 e325d5f23b859196115f10617c2f343790e07405aa0c7fadf45cd2e95fa87ec2

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a57d7ba9ea7003f0f6b2ef103551de905bc09a85c745036ec40d3a7d6d7f7be5
MD5 7ed19bf6f3f7af2c214aebf6fddce391
BLAKE2b-256 373e48fec27cc887d9c3e536abf2715180d95f24f2e276c45fd6220020fcd213

See more details on using hashes here.

File details

Details for the file psbtree-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fa80e251e7e492f437fdef1156107f9ba1a44cdb08802c51eb7afd680726887
MD5 0997bf258a8c13cc2098cd15e17e3380
BLAKE2b-256 b9f230b369f3212448aa6169c685f24c931e8baa7d347c0497e448ced2693367

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page