Skip to content

Add Pause and SequenceWithBlackboardMemory BT nodes #5247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

redvinaa
Copy link
Contributor

@redvinaa redvinaa commented Jun 9, 2025

Basic Info

Info Please fill out this column
Ticket(s) this addresses (add tickets here #5213)
Primary OS tested on Ubuntu
Robotic platform tested on custom robot
Does this PR contain AI generated software? No

Description of contribution in a few bullet points

Description of documentation updates required from your changes

  • Headers are well-documented
  • Added 2 new control nodes, they need to be described in the docs with examples (create mwe from the code in the discussion)

Description of how this change was tested

  • Have been using for a long time on humble, now on jazzy
  • Haven't tested on rolling, because I don't have a rolling stack

Future work that may be required in bullet points

  • Tests still need to be written for both BT nodes!

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 93.51852% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...r_tree/plugins/control/pause_resume_controller.cpp 94.36% 4 Missing ⚠️
...lugins/control/sequence_with_blackboard_memory.cpp 89.28% 3 Missing ⚠️
Files with missing lines Coverage Δ
...r_tree/plugins/control/pause_resume_controller.hpp 100.00% <100.00%> (ø)
...lugins/control/sequence_with_blackboard_memory.hpp 100.00% <100.00%> (ø)
...lugins/control/sequence_with_blackboard_memory.cpp 89.28% <89.28%> (ø)
...r_tree/plugins/control/pause_resume_controller.cpp 94.36% <94.36%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

So this is missing tests coverage - but you know that :-) Also make sure to fix DCO

@@ -0,0 +1,98 @@
// Copyright (c) 2019 Intel Corporation
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 all of these should be updated :-)

Copy link
Member

Choose a reason for hiding this comment

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

@redvinaa I meant updated with your company since you wrote these :-)

@@ -390,6 +390,15 @@

<Control ID="RoundRobin"/>

<Control ID="Pause">
Copy link
Member

Choose a reason for hiding this comment

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

Note: Add to the docs.nav2.org for new pages for these 2 nodes + migration guide update for the nodes and how to use them for pause / resume navigation behavior within the BT

BT::NodeStatus Pause::tick()
{
unsigned int children_count = children_nodes_.size();
if (children_count < 1 || children_count > 4) {
Copy link
Member

Choose a reason for hiding this comment

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

Docs on the < 1 || > 4 is important. I'd add it both in the header doxygen, the BT walkthrough or tutorial, and the configuration guide page.

Copy link
Contributor

mergify bot commented Jun 10, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@redvinaa
Copy link
Contributor Author

Woah, this suddenly became more serious than I expected :D
I still have to write the tests and make this work with my jazzy stack, so it might take some time.

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

Woah, this suddenly became more serious than I expected :D

I think this is really great work! Definitely happy to have it contributed! 🥇

I still have to write the tests and make this work with my jazzy stack, so it might take some time.

OK! Only really nitpicks, tests, and doc updates left in my book


void switchState(const state_t new_state);

rclcpp::Node::SharedPtr node_;
Copy link
Member

Choose a reason for hiding this comment

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

Store the logger not the node please

}

if (state_ != PAUSED) {
RCLCPP_INFO(node_->get_logger(), "PAUSE_REQUESTED");
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 log can be a little more than this 😉

}

if (state_ == PAUSED) {
RCLCPP_INFO(node_->get_logger(), "RESUME_REQUESTED");
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 log can be a little more than this 😉

* - resume_service_name: name of the service to resume
*
* Usage:
* <Pause pause_service_name="/pause" resume_service_name="/resume">
Copy link
Member

Choose a reason for hiding this comment

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

Can we work a little on the naming here: Unpaused --> Active? Resume? Processing?

Unpaused gave me a bit of back and forth to understand & the ON_RESUME branch is using the word "resume" on "unpaused".


Also, Pause should now be PauseResumeController

BT::NodeStatus PauseResumeController::tickChildAndTransition()
{
// Return RUNNING and do nothing if specific child is not used
const uint child_idx = child_indices.at(state_);
Copy link
Member

@SteveMacenski SteveMacenski Jun 10, 2025

Choose a reason for hiding this comment

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

Type out (here and anywhere else) unsigned int. This helps with windows compatibility

BT::NodeStatus PauseResumeController::tickChildAndTransition()
{
// Return RUNNING and do nothing if specific child is not used
const uint child_idx = child_indices.at(state_);
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this logic in the switchState function? Switch to the correct state if not implemented so that when tickChildAndTransition is called we do useful work.

Copy link
Contributor

mergify bot commented Jun 20, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

1 similar comment
Copy link
Contributor

mergify bot commented Jun 20, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@redvinaa
Copy link
Contributor Author

@SteveMacenski I started writing the tests and I have a few questions.

The dummy BT node used for tests now returns IDLE after reset. Shouldn't it always return the status that it was set to?
The SequenceWithBlackboardMemoryNode logic has a resetChildren call, and all the dummy nodes return IDLE after it, making the tests fail.

Also, could you give me some pointers on how to write tests for the SequenceWithBlackboardMemoryNode? It needs changing the value of input ports between tests. I only found tests where the input port values are set in the SetUp part, but that cannot be parameterized. I also tried creating a new BT node instance for every single test, but I haven't managed to make that work yet, and even if I did, it wouldn't be a nice solution.

@redvinaa
Copy link
Contributor Author

I found the bug which didn't let me set current_child_idx input_port: #5295

@SteveMacenski
Copy link
Member

SteveMacenski commented Jul 2, 2025

Sorry for the delay - I've been underwater the last couple of weeks and now committing today to get through my email review backlog. I apologize for the delay and thank you for your help!

For tests, you can do something more in the theme of the action nodes: https://github.com/ros-navigation/navigation2/blob/main/nav2_behavior_tree/test/plugins/action/test_append_goal_pose_to_goals_action.cpp. Here, we make an example BT XML that is loaded and used instead. This is actually a better way to write the tests IMO and the dummy node manual tree population done in the control test you linked to is an outdated way. We know those can have some problems since the tree isn't being constructed in the same way it would be in an application. You could still potentially use a dummy node within the tree, but the tree itself is constructed fully, including the ports and blackboard.

That way, the blackboard of the BT is maintained between ticks since it acts like a proper behavior tree (because it is one). I think that answers your question!

@redvinaa redvinaa marked this pull request as ready for review July 4, 2025 13:27
Copy link
Contributor

mergify bot commented Jul 4, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@redvinaa
Copy link
Contributor Author

redvinaa commented Jul 4, 2025

I've implemented the tests using xml strings as in the action nodes, and DummyNodes. I've had to be creative, because none of the existing tests needed this level of complexity. Tell me what you think of this solution @SteveMacenski. I've added a new header file to access nodes from the tree and cast them to the correct type. I also had to modify the DummyNode implementation a bit, so it returns IDLE after resetting, but on tick it again returns the state that it was set to. I don't think it breaks existing tests.

Copy link
Contributor

mergify bot commented Jul 4, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Jul 8, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

1 similar comment
Copy link
Contributor

mergify bot commented Jul 8, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Jul 8, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@redvinaa redvinaa force-pushed the pause-bt-nodes branch 2 times, most recently from 55be1a2 to dd67e94 Compare July 8, 2025 14:36
Copy link
Contributor

mergify bot commented Jul 8, 2025

@redvinaa, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Jul 10, 2025

This pull request is in conflict. Could you fix it @redvinaa?

redvinaa added 8 commits July 11, 2025 09:57
Signed-off-by: redvinaa <[email protected]>
Signed-off-by: redvinaa <[email protected]>
Signed-off-by: redvinaa <[email protected]>
Signed-off-by: redvinaa <[email protected]>
Signed-off-by: redvinaa <[email protected]>
@redvinaa
Copy link
Contributor Author

@SteveMacenski can you take a look at this?

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.

2 participants