Skip to content

added parallel node for BT#141

Open
ste93 wants to merge 11 commits intomainfrom
feat/parallel_node
Open

added parallel node for BT#141
ste93 wants to merge 11 commits intomainfrom
feat/parallel_node

Conversation

@ste93
Copy link
Member

@ste93 ste93 commented Oct 28, 2025

added parallel node for BT, needed for UC3

@ste93 ste93 force-pushed the feat/parallel_node branch from dcf942b to 0147311 Compare February 4, 2026 09:54
@ste93 ste93 self-assigned this Mar 4, 2026
@ste93 ste93 requested review from EnricoGhiorzi and ct2034 March 5, 2026 09:35
ste93 added 5 commits March 5, 2026 11:04
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
@ste93 ste93 force-pushed the feat/parallel_node branch from ed9c0bb to 3aa4aa4 Compare March 5, 2026 10:04
ste93 added 5 commits March 5, 2026 15:22
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
@ste93 ste93 marked this pull request as ready for review March 6, 2026 10:33
@ste93
Copy link
Member Author

ste93 commented Mar 6, 2026

@ct2034 @EnricoGhiorzi I've added the parallel node (needed for UC3) can you check this PR and if it is good we can merge it

@EnricoGhiorzi
Copy link
Contributor

EnricoGhiorzi commented Mar 7, 2026

I tried pulling the PR and building the UC3 model with a parallel node but I see no such nodes in the generated files. Is this to be expected? Is there a way to have a compiled parallel node to test?

PS: I managed to compile the bt with the parallel node (I had to uncomment some stuff in NotifyUserComponent so the model might not work as intended). Generation of the node works well but verification still shows that the battery alarm is never raised, though I am not sure whether that depends on the Parallel node.

PPS: I had forgot to change the property to include the BatteryAlarmSkill which is now included in the model. This allowed me to verify that the battery properties actually run fine! The robot still does not charge its battery, but that was to be expected I believe. Anyway, at least in this test, the parallel node seems to be working.

Copy link
Contributor

@EnricoGhiorzi EnricoGhiorzi left a comment

Choose a reason for hiding this comment

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

Thank you @ste93 for the PR. I think the parallel node is mostly working, also based on empirical sperimentation, but there are a few points in the code (marked with relevant comments) that I think could be improved before we merge this.

<assign location="success_count" expr="0" />
<assign location="failure_count" expr="0" />
</onentry>
<transition cond="children_count == 0" target="wait_for_tick">
Copy link
Contributor

Choose a reason for hiding this comment

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

On state init the first transition prevents children_count to be equal to 0 so this condition should never be satisfied.

</transition>
</state>

<state id="advance_child">
Copy link
Contributor

Choose a reason for hiding this comment

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

This state is never reached so it should be safe to delete.

<transition target="tick_current_child" />
</state>

<state id="eval_thresholds">
Copy link
Contributor

Choose a reason for hiding this comment

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

This state is never reached so it should be safe to delete.

<bt_return_status status="SUCCESS" />
</transition>

<bt_child_halted id="current_child_idx" target="halting_after_success_next" />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is no need for the state halting_after_success_next, just modify this transition as:

<bt_child_halted id="current_child_idx" target="halting_after_success">
    <assign location="current_child_idx" expr="current_child_idx + 1" />
</bt_child_halted>

Similar comments apply for halting_after_failure_next and halting_on_parent_halt_next.


<!-- Loop and counters -->
<data id="current_child_idx" type="int8" expr="0" />
<data id="success_count" type="int16" expr="0" />
Copy link
Contributor

Choose a reason for hiding this comment

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

The variables success_count and failure_count are declared as 16-bit integers, but should be the same type as all others, i.e., int8. Even better, all variables could be uint8 as we don't really need them to go negative.

@@ -0,0 +1,14 @@
<!-- Test that the Parallel node fails when failure_threshold is met:
- 3 children where 1 keeps running, 2 return failure immediately
Copy link
Contributor

Choose a reason for hiding this comment

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

Example is inconsistent with description: two nodes always succeed and one always fails.

@@ -0,0 +1,14 @@
<!-- Test that the Parallel node succeeds when success_threshold is met:
- 3 children where 2 return success immediately, 1 keeps returning running
Copy link
Contributor

Choose a reason for hiding this comment

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

Example is inconsistent with description: third node always fails instead of running.

Copy link
Contributor

Choose a reason for hiding this comment

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

status_action is never used in the test BTs so its code never runs. I think we should use status_action in the test BTs in place of/in addition to the AlwaysFailure and AlwaysSuccess nodes already there. Similar comments apply to main_test_parallel_running.xml and main_test_parallel_success.xml.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test is never invoked so it will not run. To run it we also need a relevant property to check, which I think could be something like "always running".

Signed-off-by: Stefano Bernagozzi <stefano.bernagozzi@iit.it>
@ste93
Copy link
Member Author

ste93 commented Mar 11, 2026

@EnricoGhiorzi I should have addressed most of the comments

"parallel_failure_test",
expected_result_probability=1.0,
)

Copy link
Member

Choose a reason for hiding this comment

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

I think the main_test_parallel_running is missing. Are you planning to add that?

</parameters>

<behavior_tree>
<input type="bt.cpp-xml" src="./bt_test_parallel_running.xml" />
Copy link
Member

Choose a reason for hiding this comment

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

I think this file is missing.

Copy link
Member

@ct2034 ct2034 left a comment

Choose a reason for hiding this comment

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

Thanks Stefano. This looks really good. The tests worked for me.

I just noticed that you also created main_test_parallel_running.xml but not the bt for it. I think that would be worth testing, too.

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.

3 participants