Skip to content

Add Behavior Tree#83

Merged
Seongoo merged 96 commits intomainfrom
feature-behavior-tree
Jan 26, 2026
Merged

Add Behavior Tree#83
Seongoo merged 96 commits intomainfrom
feature-behavior-tree

Conversation

@Seongoo
Copy link
Member

@Seongoo Seongoo commented Jan 23, 2026

Add physical_ai_bt package for behavior tree execution

This commit introduces the physical_ai_bt package, a Python-based behavior tree
framework for executing hierarchical task sequences on physical AI robots.

Package Overview:

  • ROS 2 node for loading and executing behavior trees from XML files
  • Tick-based execution at configurable rates (default 30Hz)
  • Support for ffw_sg2_rev1 robot type through configuration
  • Automatic node shutdown after tree completion

Key Components:

  1. BehaviorTreeNode: Main ROS 2 node that loads and executes behavior trees
  2. Action Nodes: MoveArms, MoveHead, MoveLift, Rotate, Inference
  3. Control Nodes: Sequence for sequential task execution
  4. TreeLoader: XML parser for loading behavior tree definitions
  5. Blackboard: Shared data storage for inter-node communication

@Seongoo Seongoo self-assigned this Jan 23, 2026
@Seongoo Seongoo added the enhancement New feature or request label Jan 23, 2026
Copilot AI review requested due to automatic review settings January 23, 2026 04:44
@Seongoo Seongoo added this to Platform Jan 23, 2026
@github-project-automation github-project-automation bot moved this to 🌱 Todo in Platform Jan 23, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @Seongoo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a behavior tree system for physical AI robots, enabling complex task sequences to be executed. It includes a new ROS 2 package with action and control nodes, XML-based tree configuration, and integration with the existing physical_ai_server for controlling inference and action publishing.

Highlights

  • New Package: physical_ai_bt: Introduces a new ROS 2 package, physical_ai_bt, which provides a behavior tree framework for controlling physical AI robots. It includes nodes for loading and executing behavior trees from XML files.
  • Action Nodes: Implements several action nodes such as MoveArms, MoveHead, MoveLift, and Rotate to control robot movements, along with a Sequence control node for sequential task execution.
  • Configuration and Parameters: Adds a launch file (bt_node.launch.py) and parameter files (bt_node_params.yaml) for configuring the behavior tree node, including robot type, tree XML file, and tick rate.
  • Control Inference Service: Adds a new service to physical_ai_server that allows external BT nodes to pause inference and enable/disable action publishing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/ros-ci.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Seongoo Seongoo moved this from 🌱 Todo to 📝 Pull Request in Platform Jan 23, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the physical_ai_bt package, a Python-based behavior tree framework for executing hierarchical task sequences on physical AI robots. It provides XML-based tree definitions, tick-based execution at configurable rates, and support for multiple robot types.

Changes:

  • Added new physical_ai_bt package with core behavior tree functionality
  • Modified physical_ai_server to support action publishing control during inference
  • Updated version numbers across packages to 0.8.0

Reviewed changes

Copilot reviewed 36 out of 39 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
physical_ai_bt/physical_ai_bt/bt_node.py Main ROS 2 node for loading and executing behavior trees with automatic shutdown
physical_ai_bt/physical_ai_bt/bt_nodes_loader.py XML parser for loading behavior tree definitions and instantiating nodes
physical_ai_bt/physical_ai_bt/actions/base_action.py Base classes for behavior tree nodes (BTNode, BaseAction, BaseControl)
physical_ai_bt/physical_ai_bt/actions/rotate.py Action node for rotating mobile base using odometry feedback
physical_ai_bt/physical_ai_bt/actions/move_arms.py Action node for moving both robot arms to target joint positions
physical_ai_bt/physical_ai_bt/actions/move_head.py Action node for moving robot head joints
physical_ai_bt/physical_ai_bt/actions/move_lift.py Action node for moving robot lift to specified position
physical_ai_bt/physical_ai_bt/controls/sequence.py Sequence control node for sequential child execution
physical_ai_bt/physical_ai_bt/blackboard.py Singleton blackboard for sharing data across nodes
physical_ai_server/physical_ai_server/physical_ai_server.py Added inference control service and action publish pause functionality
physical_ai_server/physical_ai_server/communication/communicator.py Added action publish enable/disable flag
physical_ai_server/config/omx_f_config.yaml Updated camera topic configuration
physical_ai_server/config/ffw_sg2_rev1_config.yaml Fixed camera topic and trailing whitespace
physical_ai_tools/package.xml Added physical_ai_bt dependency
rosbag_recorder/CHANGELOG.rst Updated changelog with release date
physical_ai_bt/trees/ffw_sg2_rev1.xml Example behavior tree definition for FFW SG2 Rev1 robot
Files not reviewed (1)
  • physical_ai_manager/package-lock.json: Language not supported
Comments suppressed due to low confidence (3)

rosbag_recorder/CHANGELOG.rst:1

  • The changelog entry uses a date of 2026-01-19, which is in the future. The current date is January 23, 2026, so this date is actually in the past. However, it appears this should reference 2025-01-19 based on typical versioning patterns.
    physical_ai_tools/CHANGELOG.rst:1
  • The changelog entry uses a date of 2026-01-19, which is in the future. The current date is January 23, 2026, so this date is actually in the past. However, it appears this should reference 2025-01-19 based on typical versioning patterns.
    physical_ai_bt/physical_ai_bt/bt_node.py:1
  • The default tree_xml parameter is 'ffw_test.xml', but this file doesn't appear to exist in the trees directory. Only 'ffw_sg2_rev1.xml' is present. Consider updating the default to match an existing file or ensuring ffw_test.xml is included.
#!/usr/bin/env python3

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive behavior tree framework in the physical_ai_bt package, which is a significant and well-structured addition. The design, including the use of threads for non-blocking actions and XML-based tree definitions, is solid. I've provided several comments to address a high-severity bug in the MoveHead action, improve consistency across the action node implementations, and suggest some code cleanup and refactoring for better maintainability. The integration with physical_ai_server to allow the behavior tree to control the robot appears to be correctly implemented.

@Seongoo Seongoo marked this pull request as draft January 23, 2026 04:49
@Seongoo Seongoo requested review from kimtaehyeong99 and ola31 and removed request for kimtaehyeong99 and ola31 January 23, 2026 05:07
@Seongoo Seongoo marked this pull request as ready for review January 23, 2026 05:48
@Seongoo Seongoo force-pushed the feature-behavior-tree branch from dbb72b1 to 8cf08d9 Compare January 23, 2026 07:20
@Seongoo Seongoo force-pushed the feature-behavior-tree branch from b960ea6 to 7eda1f0 Compare January 23, 2026 08:16
@kimtaehyeong99 kimtaehyeong99 self-requested a review January 23, 2026 08:45
Copy link
Member

@ola31 ola31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

()

@Seongoo Seongoo requested a review from ola31 January 26, 2026 01:53
Copy link
Member

@ola31 ola31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@kimtaehyeong99 kimtaehyeong99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOOD!

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Add comprehensive docstrings to all modules, classes, and methods
- Fix import ordering (stdlib, third-party, local imports)
- Change double quotes to single quotes throughout
- Fix line length issues (max 99 characters)
- Add noqa comments for unavoidable style warnings (I100, A003)
- Create test infrastructure with test_flake8.py and test_pep257.py
- Add test dependencies to package.xml
- Create .flake8 configuration file
- Update setup.cfg with flake8 settings

All files now pass ament_flake8 and ament_pep257 checks.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Automatically shutdown the BT node when behavior tree execution completes
(either SUCCESS or FAILURE). This allows the node to exit cleanly after
finishing its task instead of running indefinitely.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Add missing else clause when joint not found in /joint_states
- Add warning logs for missing joints in MoveArms, MoveHead, MoveLift
- Prevent premature success when joints are missing from state message

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Remove Isaac-GR00T submodule from git tracking
- Add Isaac-GR00T/, install/, log/ to .gitignore
- Keep physical directory for local use but exclude from version control

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Combine left and right arm joint checking into a single loop by
merging joint_names and positions lists. This eliminates code
duplication and improves maintainability.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
The Rotate action uses Twist messages for mobile base rotation,
not JointTrajectory messages. Removed the unused trajectory_pub
and its import to improve code clarity.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Add AGENTS.md to .gitignore for project documentation
- Remove redundant bt_node entry point from setup.py

The physical_ai_bt entry point is sufficient and more descriptive
than the generic bt_node name.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Add else clause to _load_node method to raise ValueError when
encountering unknown node types or IDs. This prevents silent
failures and makes debugging easier.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Reorganize behavior tree base classes into clearer file structure:
- Create bt_core.py for BTNode and NodeStatus (core classes)
- Update actions/base_action.py to only contain BaseAction
- Create controls/base_control.py for BaseControl and BaseDecorator
- Update all imports across action and control files

This improves code maintainability by placing each class in an
appropriately named location that reflects its purpose.

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Create physical_ai_bt/constants.py with descriptive constant names
- Update all action files (move_arms, move_head, move_lift, rotate) to use constants
- Improve code self-documentation and maintainability
- No functional changes, purely refactoring

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Add DEFAULT joint name constants to MoveArms, MoveHead, MoveLift
- Update action constructors to accept optional joint_names parameters
- Add TreeLoader helper to extract joint names from topic_config
- Pass configured joint names from TreeLoader to action instances
- Maintain backward compatibility with hardcoded defaults
- Support different robot types through configuration alone

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Add threading.Lock to protect shared result state
- Add threading.Event for clean thread signaling and shutdown
- Replace _thread_done/_thread_success with lock-protected _result
- Ensure thread-safe access in tick(), _control_loop(), and reset()
- Apply fix to all action classes (MoveArms, MoveHead, MoveLift, Rotate)
- Prevent torn reads, stale values, and undefined behavior

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
- Remove control_action_publish_callback method (never registered as service)
- Remove action_publish_enabled flag (always True, never changed)
- Remove inference_paused flag (no service to control it)
- Simplify publish_action method to always publish
- No functional impact as BT never uses this functionality

Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
Signed-off-by: Seongwoo Kim <kimsw@robotis.com>
@Seongoo Seongoo force-pushed the feature-behavior-tree branch from a34dab5 to 95547a2 Compare January 26, 2026 09:18
@Seongoo Seongoo merged commit 1dbd703 into main Jan 26, 2026
10 checks passed
@Seongoo Seongoo deleted the feature-behavior-tree branch January 26, 2026 09:32
@github-project-automation github-project-automation bot moved this from 📝 Pull Request to 🚩Done in Platform Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants