-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update BT nodes to use callback groups / executors to process #2334
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
Merged
SteveMacenski
merged 6 commits into
ros-navigation:main
from
wyca-robotics:BT_nodes_use_callback_groups
May 18, 2021
+97
−22
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a6580a
Update BT nodes to use callback groups / executors to process
aae426b
add executor to other BT nodes
a43e4a8
use spin_some in is_battery_low BT condition
88e5d9e
Merge remote-tracking branch 'ros-planning/main' into BT_nodes_use_ca…
cfa7d70
fix merge
6b50aad
remove spinning thread
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ class BtActionNode : public BT::ActionNodeBase | |
| : BT::ActionNodeBase(xml_tag_name, conf), action_name_(action_name) | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A note in the migration guide would be great that the BT nodes now have separate executors to ensure deterministic spinning of only the relevant data sources to each BT node |
||
| node_ = config().blackboard->template get<rclcpp::Node::SharedPtr>("node"); | ||
| callback_group_ = node_->create_callback_group( | ||
| rclcpp::CallbackGroupType::MutuallyExclusive, | ||
| false); | ||
| callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface()); | ||
|
|
||
| // Get the required items from the blackboard | ||
| bt_loop_duration_ = | ||
|
|
@@ -82,7 +86,7 @@ class BtActionNode : public BT::ActionNodeBase | |
| void createActionClient(const std::string & action_name) | ||
| { | ||
| // Now that we have the ROS node to use, create the action client for this BT action | ||
| action_client_ = rclcpp_action::create_client<ActionT>(node_, action_name); | ||
| action_client_ = rclcpp_action::create_client<ActionT>(node_, action_name, callback_group_); | ||
|
|
||
| // Make sure the server is actually there before continuing | ||
| RCLCPP_DEBUG(node_->get_logger(), "Waiting for \"%s\" action server", action_name.c_str()); | ||
|
|
@@ -223,7 +227,7 @@ class BtActionNode : public BT::ActionNodeBase | |
| } | ||
| } | ||
|
|
||
| rclcpp::spin_some(node_); | ||
| callback_group_executor_.spin_some(); | ||
|
|
||
| // check if, after invoking spin_some(), we finally received the result | ||
| if (!goal_result_available_) { | ||
|
|
@@ -262,7 +266,7 @@ class BtActionNode : public BT::ActionNodeBase | |
| { | ||
| if (should_cancel_goal()) { | ||
| auto future_cancel = action_client_->async_cancel_goal(goal_handle_); | ||
| if (rclcpp::spin_until_future_complete(node_, future_cancel, server_timeout_) != | ||
| if (callback_group_executor_.spin_until_future_complete(future_cancel, server_timeout_) != | ||
| rclcpp::FutureReturnCode::SUCCESS) | ||
| { | ||
| RCLCPP_ERROR( | ||
|
|
@@ -291,7 +295,7 @@ class BtActionNode : public BT::ActionNodeBase | |
| return false; | ||
| } | ||
|
|
||
| rclcpp::spin_some(node_); | ||
| callback_group_executor_.spin_some(); | ||
| auto status = goal_handle_->get_status(); | ||
|
|
||
| // Check if the goal is still executing | ||
|
|
@@ -340,7 +344,8 @@ class BtActionNode : public BT::ActionNodeBase | |
| } | ||
|
|
||
| auto timeout = remaining > bt_loop_duration_ ? bt_loop_duration_ : remaining; | ||
| auto result = rclcpp::spin_until_future_complete(node_, *future_goal_handle_, timeout); | ||
| auto result = | ||
| callback_group_executor_.spin_until_future_complete(*future_goal_handle_, timeout); | ||
| elapsed += timeout; | ||
|
|
||
| if (result == rclcpp::FutureReturnCode::INTERRUPTED) { | ||
|
|
@@ -383,6 +388,8 @@ class BtActionNode : public BT::ActionNodeBase | |
|
|
||
| // The node that will be used for any ROS operations | ||
| rclcpp::Node::SharedPtr node_; | ||
| rclcpp::CallbackGroup::SharedPtr callback_group_; | ||
| rclcpp::executors::SingleThreadedExecutor callback_group_executor_; | ||
|
|
||
| // The timeout value while waiting for response from a server when a | ||
| // new action goal is sent or canceled | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.