Skip to main content

ROS 2 base classes for the BTEng behavior tree engine

Project description

bteng-ros2

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.

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

rclpy.spin(bt)
bt.halt()
rclpy.shutdown()

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]))

License

Apache 2.0

Project details


Download files

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

Source Distribution

bteng_ros2-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

bteng_ros2-0.1.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file bteng_ros2-0.1.0.tar.gz.

File metadata

  • Download URL: bteng_ros2-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for bteng_ros2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a9725b2a462a1e4771d12afb3bced43591deae71c6bf99d917ec8cdbdac4ae4
MD5 e11f088dc7bcd4363a36db4f9df42ff9
BLAKE2b-256 fb7386d22f5ccbb974833f61c5b4986a8d504125d90d5c95bb94a6841acc6fd3

See more details on using hashes here.

File details

Details for the file bteng_ros2-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bteng_ros2-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for bteng_ros2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 228eb5a3c878703214dadfb56423567dcd5bc83fec30b2821b88bf4d3e5157a1
MD5 ca058ce6159c3ab3277d04a25f51a5e1
BLAKE2b-256 88fd12745db5a9ea8f28707bac255de0c9c1cdc456c4e07d85445bd61e9adb19

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