Metadata-Version: 2.4
Name: bteng-ros2
Version: 0.4.0
Summary: ROS 2 base classes for the BTEng behavior tree engine
Author: BTEng contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/BTEng-dev/bteng-ros2
Project-URL: Bug Tracker, https://github.com/BTEng-dev/bteng-ros2/issues
Keywords: behavior-tree,robotics,ros2,automation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: bteng<0.5,>=0.4.0
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/BTEng-dev/bteng-ros2/main/docs/images/BTEng-ROS2.webp" alt="bteng-ros2 — ROS 2 extension for BTEng" width="720">
</p>

# bteng-ros2

[![Python](https://img.shields.io/badge/python-3.12%2B-blue)](https://www.python.org/)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/BTEng-dev/bteng-ros2/blob/main/LICENSE)
[![Version](https://img.shields.io/badge/version-0.4.0-green)](https://github.com/BTEng-dev/bteng-ros2/blob/main/pyproject.toml)
[![bteng](https://img.shields.io/badge/bteng-%3E%3D0.4.0%2C%3C0.5-blue)](https://pypi.org/project/bteng/)

ROS 2 base classes for the [BTEng](https://pypi.org/project/bteng/) behavior tree engine.

A pure Python pip library. No ROS 2 workspace or colcon required. `bteng-ros2`
provides **mixins and base classes** — not a standalone node. Users inherit
from them inside their own ROS 2 packages.

- **Pre-combined bases** — `RosActionNode`, `RosServiceNode`, `RosConditionNode`, `RosStatefulActionNode`
- **Mixins** that combine freely — `RosNodeMixin`, `RosActionClientMixin`, `RosServiceClientMixin`, `RosTopicMixin`
- **Two executors** — `RosBTExecutor` (plain `rclpy.Node`) and `LifecycleBTExecutor` (managed bringup)
- **Retargetable endpoints** — `action_name` / `service_name` / `topic_name` are input ports, so a tree can point one node class at another server
- **Discovery-tolerant** — action and service nodes wait for their server (`RUNNING`, up to `discovery_timeout`, 5.0 s) without blocking the tree
- **Imports without rclpy** — define, build and unit-test trees off-robot against `FakeRosNode`; only constructing an executor needs ROS 2

## Install

```bash
source /opt/ros/jazzy/setup.bash    # or kilted / rolling — Python 3.12+
pip install bteng-ros2
```

`bteng` is pulled in automatically (pin: `bteng>=0.4.0,<0.5`). Supported ROS 2
distributions and development installs are in
[Getting started](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/getting-started.md).

## Usage

```python
import rclpy
from bteng import SequenceNode, Tree, TreeMetadata, ExecutorConfig
from bteng_ros2 import RosActionNode, RosBTExecutor
from nav2_msgs.action import NavigateToPose

class Navigate(RosActionNode):
    action_type = NavigateToPose
    action_name = "/navigate_to_pose"

    def make_goal(self):
        goal = NavigateToPose.Goal()
        goal.pose = self.blackboard.get("target_pose")
        return goal

    def on_success(self):
        self.blackboard.set("arrived", True)

rclpy.init()
root = SequenceNode("root", children=[Navigate("nav")])  # no ros_node needed at construction
tree = Tree(TreeMetadata(id="robot"), root)

bt = RosBTExecutor(tree, ExecutorConfig(tick_interval=0.05))  # injects itself into nav
status = bt.run(timeout=60.0)   # spins until the tree settles, then returns
bt.destroy_node()
rclpy.shutdown()
```

In an XML tree the endpoint is an attribute; say nothing and the class attribute is used.
The XML parser only knows registered tags, so decorate the class with `@register_node("Navigate")`
(`from bteng import register_node`) before loading it:

```xml
<root BTEng_format="1.0">
  <BehaviorTree ID="robot">
    <Navigate name="robot2" action_name="/robot2/navigate_to_pose" />
  </BehaviorTree>
</root>
```

Two runnable programs live in
[`examples/`](https://github.com/BTEng-dev/bteng-ros2/blob/main/examples). Neither
needs a ROS 2 install — both drive the real node classes against `FakeRosNode`:

```bash
python3 examples/01_robot_ready.py       # topic-driven conditions guarding actions
python3 examples/02_industrial_cell.py   # ReactiveSequence + e-stop, RetryUntilSuccessful, Timeout, service call
```

## Documentation

| Page | Covers |
|---|---|
| [Overview](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/README.md) | Design, class map, quick start, examples |
| [Getting started](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/getting-started.md) | Install, supported ROS 2 distributions, first node |
| [Node types](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/nodes.md) | The four base classes, endpoint ports, discovery |
| [Mixins](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/mixins.md) | Mixin reference and free composition |
| [Executors](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/executors.md) | `RosBTExecutor` vs `LifecycleBTExecutor`, `run()`, sharing an rclpy node |
| [Testing](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/testing.md) | `FakeRosNode`, what works with no rclpy at all |
| [Changelog](https://github.com/BTEng-dev/bteng-ros2/blob/main/docs/changelog.md) | What changed, and why |

## License

MIT — see [LICENSE](https://github.com/BTEng-dev/bteng-ros2/blob/main/LICENSE).

The third-party licence audit ships inside the package at
`bteng_ros2/licenses/THIRD_PARTY_LICENSES.md`. `pip install bteng-ros2` pulls
exactly one package, `bteng`, which is MIT with no runtime dependencies.
