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.2.tar.gz (18.0 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.2-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bteng_ros2-0.1.2.tar.gz
  • Upload date:
  • Size: 18.0 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.2.tar.gz
Algorithm Hash digest
SHA256 86a3bcc1227f2c8408e0b9783d56dfe37a8ae6f3a1156b8861c4b87d58b7ea4f
MD5 ee801312e9783836788e0d51e774e534
BLAKE2b-256 f8cc88ddf27136a99cf34020dd9eb93689b4a36b1249dc47b5970beb32ace17f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bteng_ros2-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe748da5b6c24ae16bdd546a2fbd5549d6c4466458a71f1b0135de9a077e5044
MD5 9ebf46e73c9236e8cbda8fa7d8d66de4
BLAKE2b-256 9bfd9b7a5bd76500bd32f39623df1f3e5ca31c2f49ccc647f3e059b66d008837

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