-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Draft: Added GoalUpdatedController BT plugin node #3044
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 7 commits into
ros-navigation:main
from
relffok:adding-goal-updated-controller-bt-plugin
Jun 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60cf69f
first draft for goal updated controller
relffok 4bc3126
added goal_updated_controller to all yamls
relffok 511d1ce
added GoalUpdatedController API
relffok 69d4270
added GoaUpdatedController to default plugins
relffok 8f140f9
removed first_time param
relffok ff50102
added test for GoalUpdatedController
relffok bd9095c
linter fix
relffok 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
69 changes: 69 additions & 0 deletions
69
nav2_behavior_tree/include/nav2_behavior_tree/plugins/decorator/goal_updated_controller.hpp
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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) 2018 Intel Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATED_CONTROLLER_HPP_ | ||
| #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATED_CONTROLLER_HPP_ | ||
|
|
||
| #include <chrono> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "behaviortree_cpp_v3/decorator_node.h" | ||
|
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "geometry_msgs/msg/pose_stamped.hpp" | ||
|
|
||
| namespace nav2_behavior_tree | ||
| { | ||
|
|
||
| /** | ||
| * @brief A BT::DecoratorNode that ticks its child if the goal was updated | ||
| */ | ||
| class GoalUpdatedController : public BT::DecoratorNode | ||
| { | ||
| public: | ||
| /** | ||
| * @brief A constructor for nav2_behavior_tree::GoalUpdatedController | ||
| * @param name Name for the XML tag for this node | ||
| * @param conf BT node configuration | ||
| */ | ||
| GoalUpdatedController( | ||
| const std::string & name, | ||
| const BT::NodeConfiguration & conf); | ||
|
|
||
| /** | ||
| * @brief Creates list of BT ports | ||
| * @return BT::PortsList Containing node-specific ports | ||
| */ | ||
| static BT::PortsList providedPorts() | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| private: | ||
| /** | ||
| * @brief The main override required by a BT action | ||
| * @return BT::NodeStatus Status of tick execution | ||
| */ | ||
| BT::NodeStatus tick() override; | ||
|
|
||
| bool first_time_; | ||
| bool goal_was_updated_; | ||
| geometry_msgs::msg::PoseStamped goal_; | ||
| std::vector<geometry_msgs::msg::PoseStamped> goals_; | ||
| }; | ||
|
|
||
| } // namespace nav2_behavior_tree | ||
|
|
||
| #endif // NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATED_CONTROLLER_HPP_ |
93 changes: 93 additions & 0 deletions
93
nav2_behavior_tree/plugins/decorator/goal_updated_controller.cpp
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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) 2018 Intel Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <chrono> | ||
| #include <string> | ||
|
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "geometry_msgs/msg/pose_stamped.hpp" | ||
| #include "behaviortree_cpp_v3/decorator_node.h" | ||
| #include "nav2_behavior_tree/plugins/decorator/goal_updated_controller.hpp" | ||
|
|
||
|
|
||
| namespace nav2_behavior_tree | ||
| { | ||
|
|
||
| GoalUpdatedController::GoalUpdatedController( | ||
| const std::string & name, | ||
| const BT::NodeConfiguration & conf) | ||
| : BT::DecoratorNode(name, conf), | ||
| first_time_(false) | ||
| { | ||
| } | ||
|
|
||
| BT::NodeStatus GoalUpdatedController::tick() | ||
| { | ||
| if (status() == BT::NodeStatus::IDLE) { | ||
| // Reset since we're starting a new iteration of | ||
| // the goal updated controller (moving from IDLE to RUNNING) | ||
| first_time_ = true; | ||
| goal_was_updated_ = false; | ||
| } | ||
|
|
||
| setStatus(BT::NodeStatus::RUNNING); | ||
|
|
||
| if (first_time_) { | ||
| config().blackboard->get<std::vector<geometry_msgs::msg::PoseStamped>>("goals", goals_); | ||
| config().blackboard->get<geometry_msgs::msg::PoseStamped>("goal", goal_); | ||
| } | ||
|
|
||
| std::vector<geometry_msgs::msg::PoseStamped> current_goals; | ||
| config().blackboard->get<std::vector<geometry_msgs::msg::PoseStamped>>("goals", current_goals); | ||
| geometry_msgs::msg::PoseStamped current_goal; | ||
| config().blackboard->get<geometry_msgs::msg::PoseStamped>("goal", current_goal); | ||
|
|
||
| if (goal_ != current_goal || goals_ != current_goals) { | ||
| goal_ = current_goal; | ||
| goals_ = current_goals; | ||
| goal_was_updated_ = true; | ||
| } | ||
|
|
||
| // The child gets ticked the first time through and any time the goal has | ||
| // changed or preempted. In addition, once the child begins to run, it is ticked each time | ||
| // 'til completion | ||
| if (first_time_ || (child_node_->status() == BT::NodeStatus::RUNNING) || goal_was_updated_) | ||
| { | ||
| first_time_ = false; | ||
| goal_was_updated_ = false; | ||
| const BT::NodeStatus child_state = child_node_->executeTick(); | ||
|
|
||
| switch (child_state) { | ||
| case BT::NodeStatus::RUNNING: | ||
| return BT::NodeStatus::RUNNING; | ||
|
|
||
| case BT::NodeStatus::SUCCESS: | ||
| return BT::NodeStatus::SUCCESS; | ||
|
|
||
| case BT::NodeStatus::FAILURE: | ||
| default: | ||
| return BT::NodeStatus::FAILURE; | ||
| } | ||
| } | ||
|
|
||
| return status(); | ||
| } | ||
|
|
||
| } // namespace nav2_behavior_tree | ||
|
|
||
| #include "behaviortree_cpp_v3/bt_factory.h" | ||
| BT_REGISTER_NODES(factory) | ||
| { | ||
| factory.registerNodeType<nav2_behavior_tree::GoalUpdatedController>("GoalUpdatedController"); | ||
| } | ||
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
14 changes: 14 additions & 0 deletions
14
nav2_bt_navigator/behavior_trees/navigate_w_replanning_only_if_goal_is_updated.xml
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!-- | ||
| This Behavior Tree replans the global path only when the goal is updated. | ||
| --> | ||
|
|
||
| <root main_tree_to_execute="MainTree"> | ||
| <BehaviorTree ID="MainTree"> | ||
| <PipelineSequence name="NavigateWithReplanning"> | ||
| <GoalUpdatedController> <!-- only tick child if goal was updated--> | ||
|
SteveMacenski marked this conversation as resolved.
|
||
| <ComputePathToPose goal="{goal}" path="{path}" planner_id="GridBased"/> | ||
| </GoalUpdatedController> | ||
| <FollowPath path="{path}" controller_id="FollowPath"/> | ||
| </PipelineSequence> | ||
| </BehaviorTree> | ||
| </root> | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
first_time_is required, if you place the 2 initialgets inside of theif IDLEcondition above. I'm not sure (?) thatfirst_time_is required in the main if in L65.Thinking through the logic, if this is called a 2nd time, the
goal_was_updated_will be true. If the child action is still continuing, it'll tick again. So its really just the first time we need to specifically say to go for it.We could just in
if (status() == BT::NodeStatus::IDLE) {saygoal_was_updated_ = truesince its updated from the idle state reference. That would be the same logic without thefirst_time_variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this,
first_time_isn't required.Although, does it make sense for this node to tick its child when it's updated from IDLE state to RUNNING state on the first tick? The node is only meant to tick its child when goal is updated on the blackboard. But with this logic, we assume that the decorator should tick its child on the first tick and any further ticks where the goal is updated. This logic made sense for
RateControllerandDistanceControllerwhere we start the logic at 0 seconds or 0 meters traveled but I'm not sure ifGoalUpdatedcondition requires a mandatory execution of its child on its first tick, that should happen automatically on the first tick whenif (goal_ != current_goal || goals_ != current_goals)condition is true.We could just remove
first_time_and place to 2 initialgets inside theif (status() == BT::NodeStatus::IDLE)condition while settinggoal_was_updated_ = falsewithin the condition and leave everything else as it is. That would mean that this node would tick its child only when the goal is updated on the blackboard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fully agree with the
first_timeparameter, I wanted to keep it to make it obvious but since the code is so easy, it's quickly figured out.I think from the naming it makes sense not to tick the child on the first visit, I am just wondering if application-wise it makes sense to tick it anyway for the first time. Either way, it's a quick change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always tick on the first visit for this kind of thing - or else when you submitted a navigation request, it would never plan at all (you'd have to issue another new goal afterwards)