Skip to content

[ports] Top-level input port default values in behavior tree XML - #509

Merged
sea-bass merged 4 commits into
develfrom
default-top-level-ports
Aug 26, 2026
Merged

sea-bass merged 4 commits into
develfrom
default-top-level-ports

Conversation

@sea-bass

@sea-bass sea-bass commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

This PR does 2 things related to default values in tree-level input ports.

  1. Adds default ports to subtrees. For example:
<root main_tree_to_execute="MainTree">
  <BehaviorTree ID="SubTree" input1="default_str" input2="42">
    <Sequence>
      <Consumer name="Consumer" input="{input1}"/>
      <FloatConsumer name="FloatConsumer" input="{input2}"/>
    </Sequence>
  </BehaviorTree>
  
  <BehaviorTree ID="MainTree">
    <Sequence>
      <SubTree ID="SubTree" name="AllDefaults" />
      <SubTree ID="SubTree" name="FirstInputSet" input1="override_str" />
      <SubTree ID="SubTree" name="SecondInputSet" input2="67" />
      <SubTree ID="SubTree" name="BothInputsSet" input1="another_str" input2="9001" />
    </Sequence>
  </BehaviorTree>
</root>
  1. Adds default ports to the main tree, which can be overridden with a new input_mappings argument to parse_behaviour_tree_xml().
<root main_tree_to_execute="MainTree">
  <!-- input1 has a default, but input2 does not -->
  <BehaviorTree ID="MainTree" input1="default_str">
    <Sequence>
      <Consumer name="Consumer" input="{input1}"/>
      <FloatConsumer name="FloatConsumer" input="{input2}"/>
    </Sequence>
  </BehaviorTree>
</root>
root_node = parse_behaviour_tree_xml(
    self.tempfile.name,
    logger=StdoutLogger(),
    input_mappings={"input1": "override_str", "input2": "67"},
)

Tests added accordingly.

Closes #508

@sea-bass
sea-bass marked this pull request as ready for review August 15, 2026 12:07

@eholum eholum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very neat! Just being annoying and asking a (potentially obvious) question...

if k in ("ID", "name"):
continue
logger.debug(f"Checking to add new key for default BehaviorTree attribute: {k} -> {v}")
add_new_key_to_remapping_table(v, remapping_table=remapping_table, subtree_namespace=parent_namespace)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

New to this, but wondering about the scope of this remapping since the subtree namespace is the same as the parent namespace. Is the parent remapping_table the authoritative source? What value does the subtree namepsace bring here? And in particular, what would happen if two subtrees used the same port name but different values?

I might just need to spend more time reading...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

subtree_namespace keeps pre-pending namespaces down the hierarchy, so it modifies the remapping table as you recursively instantiate subtrees XML.

So basically the remapping cannot apply to 2 subtrees since they have to have unique names, and therefore have unique namespaces.

@sea-bass
sea-bass merged commit 3c75657 into devel Aug 26, 2026
5 checks passed
@sea-bass
sea-bass deleted the default-top-level-ports branch August 26, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding subtree default port remapping values

2 participants