Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.4.0 instead.

bteng-ros2 — ROS 2 extension for BTEng

bteng-ros2

Python License Version bteng

ROS 2 base classes for the BTEng behavior tree engine.

A pure Python pip library. No ROS 2 workspace or colcon required.

Install

source /opt/ros/humble/setup.bash   # or iron / jazzy
pip install bteng-ros2

bteng is pulled in automatically. bteng>=0.3.1 is required — this package's nodes rely on fixes landed in that release (execute_tick() rejecting a non-NodeStatus result, ParallelNode validating without an explicit success_threshold, reactive guards re-ticking). Older cores are not supported.

Importing without ROS 2

import bteng_ros2 succeeds on a machine with no rclpy installed, so a CLI can serve --help / --dry-run and a test suite can run off-robot:

Without rclpy Works?
import bteng_ros2, bteng_ros2.__version__ yes
Defining node classes: RosActionNode, RosServiceNode, RosConditionNode, RosStatefulActionNode, the four mixins yes
Constructing and ticking them against FakeRosNode yes
Building and validating a Tree of them yes
Subclassing RosBTExecutor / LifecycleBTExecutor yes
Constructing RosBTExecutor / LifecycleBTExecutor no — raises ImportError naming the missing rclpy symbol
Any call that reaches real ROS traffic (create_publisher on a real node, _init_action_client, …) no

The two executors are real rclpy nodes, so they cannot work without ROS; they fail loudly at construction rather than half-working. Check bteng_ros2.executor.RCLPY_AVAILABLE if your program needs to branch.

Retargetable endpoints

A subclass of RosActionNode, RosServiceNode or RosConditionNode gets its endpoint as an input port whose default is the class attribute — action_name, service_name, topic_name respectively. A tree can point one node at a second server without a subclass, and --namespace-style rewrites have something to rewrite:

<GoToWaypoint name="robot2" action_name="/robot2/navigate_to_pose" />
<GoToWaypoint name="dock"   action_name="{dock_action}" />

Say nothing and the class attribute is used. The port is appended by __init_subclass__, so subclasses that define their own provided_ports() — as most do — inherit it without calling super(). RosTopicMixin is not covered: a publisher's topic stays a class attribute.

Discovery

DDS discovery has not finished at the moment a client is created, so a node that asks service_is_ready() immediately gets "no" from a healthy stack. Every action and service node waits for its server, reporting RUNNING meanwhile, up to discovery_timeout (5.0 s; set 0.0 to require it on the first tick). The wait is spread across ticks, not blocking, so the rest of the tree keeps running.

Design

bteng-ros2 provides mixins and base classes — not a standalone node. Users inherit from them inside their own ROS 2 packages.

Mixins (combine freely)         Pre-combined bases (common patterns)
─────────────────────────       ───────────────────────────────────
RosNodeMixin                    RosActionNode
RosActionClientMixin            RosStatefulActionNode
RosServiceClientMixin           RosConditionNode
RosTopicMixin

Usage

Simple action node

from bteng_ros2 import RosActionNode
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)

Stateful node with multiple ROS capabilities

from bteng_ros2 import RosStatefulActionNode
from nav2_msgs.action import NavigateToPose
from std_msgs.msg import String

class NavigateAndPublish(RosStatefulActionNode):
    def on_start(self):
        self._pub = self.create_publisher(String, "/status", 10)
        self._init_action_client(NavigateToPose, "/navigate_to_pose")
        self.send_goal(self._build_goal())

    def on_running(self):
        self._pub.publish(String(data="navigating"))
        return self.action_status()

    def on_halted(self):
        self.cancel_goal()

Mix freely — combine only what you need

from bteng import StatefulActionNode, NodeStatus
from bteng_ros2 import RosActionClientMixin, RosTopicMixin

# Only action + topic, no service client overhead
class Navigate(RosActionClientMixin, RosTopicMixin, StatefulActionNode):
    ...

Condition from a topic

from bteng_ros2 import RosConditionNode
from sensor_msgs.msg import LaserScan

class ObstacleDetected(RosConditionNode):
    topic_type = LaserScan
    topic_name = "/scan"

    def evaluate(self, msg: LaserScan) -> bool:
        return min(msg.ranges) < 0.5

Wire into your ROS 2 node

import rclpy
from bteng import SequenceNode, Tree, TreeMetadata, ExecutorConfig
from bteng_ros2 import RosBTExecutor

rclpy.init()

nav   = Navigate("nav")        # no ros_node needed at construction
check = ObstacleDetected("obs")
root  = SequenceNode("root", children=[check, nav])
tree  = Tree(TreeMetadata(id="robot"), root)

bt = RosBTExecutor(tree, ExecutorConfig(tick_interval=0.05))
# ↑ injects itself into nav and check automatically

status = bt.run(timeout=60.0)   # spins until the tree settles, then returns
bt.destroy_node()
rclpy.shutdown()

run() is the one-tree-then-exit form: it spins, returns the root's final NodeStatus, and on timeout halts the tree and returns FAILURE. For a long-lived node that keeps serving after the tree finishes, use rclpy.spin(bt) instead. Pass ros_node= to have the tree share an rclpy node you already own rather than the executor itself.

Lifecycle variant

from bteng_ros2 import LifecycleBTExecutor

class RobotBT(LifecycleBTExecutor):
    def build_tree(self) -> Tree:
        return Tree(TreeMetadata(id="robot"), ...)

Import from bteng_ros2.lifecycle:

from bteng_ros2.lifecycle import LifecycleBTExecutor

Testing without ROS 2

from bteng_ros2.testing import FakeRosNode

fake = FakeRosNode()
node = Navigate("nav", ros_node=fake)

# Inject a fake message into a subscription
fake.subscriptions["/scan"].inject(LaserScan(ranges=[1.0, 2.0]))

# Service clients: control readiness and when the response lands
fake = FakeRosNode(service_deferred=True)      # responses wait for resolve()
node = SetParam("svc", ros_node=fake)
node.on_start()                                 # RUNNING — call in flight
fake.service_clients["/set_param"].resolve(response)

See docs/testing.md.

License

MIT

Metadata

Release files for bteng-ros2 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bteng-ros2 0.2.4
File Size Uploaded Provenance Actions
bteng_ros2-0.2.4.tar.gz 26.7 kB Without provenance Details for bteng_ros2-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bteng-ros2 0.2.4
File Interpreter ABI Platform Actions
bteng_ros2-0.2.4-py3-none-any.whl Python 3 none any Details for bteng_ros2-0.2.4-py3-none-any.whl

Total release size: 58.2 kB

Release files / bteng_ros2-0.2.4.tar.gz

Download URL bteng_ros2-0.2.4.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b423b7133b9b736593b23b9063c7c869e3aeab6105583888cda9789944f8dbde
BLAKE2b-256 checksum
How to use checksums
9594aa9ad6fe584244afdc106d2f67d9159d064f6c4834f4a35fd35b506b973d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / bteng_ros2-0.2.4-py3-none-any.whl

Download URL bteng_ros2-0.2.4-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
444009bfa962f54f1d6cb3db2241c39e7b3929cfd4458d2fc72ae1d21441dc34
BLAKE2b-256 checksum
How to use checksums
4786cb460394e537c4c4e779546daae521b356213a86bbc5e16c765731fcd9d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for bteng-ros2 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page