-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be able to invoke a single recovery action at a time (#1388)
Added parallel recovery behaviors
- Loading branch information
Showing
9 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,82 @@ | ||
// Copyright (c) 2019 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 <string> | ||
|
||
#include "behaviortree_cpp_v3/control_node.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
class RoundRobinNode : public BT::ControlNode | ||
{ | ||
public: | ||
explicit RoundRobinNode(const std::string & name) | ||
: BT::ControlNode::ControlNode(name, {}) | ||
{ | ||
setRegistrationID("RoundRobin"); | ||
} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
const unsigned num_children = children_nodes_.size(); | ||
|
||
setStatus(BT::NodeStatus::RUNNING); | ||
|
||
TreeNode * child_node = children_nodes_[current_child_idx_]; | ||
const BT::NodeStatus child_status = child_node->executeTick(); | ||
|
||
switch (child_status) { | ||
case BT::NodeStatus::SUCCESS: | ||
// Wrap around to the first child | ||
if (++current_child_idx_ == num_children) { | ||
// TODO(mjeronimo): halt this child (not all children) | ||
current_child_idx_ = 0; | ||
} | ||
|
||
haltChildren(0); | ||
return BT::NodeStatus::SUCCESS; | ||
|
||
case BT::NodeStatus::FAILURE: | ||
haltChildren(0); | ||
return BT::NodeStatus::FAILURE; | ||
|
||
case BT::NodeStatus::RUNNING: | ||
break; | ||
|
||
default: | ||
throw BT::LogicError("Invalid status return from BT node"); | ||
break; | ||
} | ||
|
||
return BT::NodeStatus::RUNNING; | ||
} | ||
|
||
void halt() override | ||
{ | ||
ControlNode::halt(); | ||
current_child_idx_ = 0; | ||
} | ||
|
||
private: | ||
unsigned int current_child_idx_{0}; | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
BT_REGISTER_NODES(factory) | ||
{ | ||
factory.registerNodeType<nav2_behavior_tree::RoundRobinNode>("RoundRobin"); | ||
} |
This file contains 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 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
30 changes: 30 additions & 0 deletions
30
nav2_bt_navigator/behavior_trees/navigate_w_replanning_and_round_robin_recovery.xml
This file contains 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,30 @@ | ||
|
||
<!-- | ||
This Behavior Tree replans the global path periodically at 1 Hz and it also has | ||
recovery actions. | ||
--> | ||
<root main_tree_to_execute="MainTree"> | ||
<BehaviorTree ID="MainTree"> | ||
<RecoveryNode number_of_retries="2" name="NavigateRecovery"> | ||
<PipelineSequence name="NavigateWithReplanning"> | ||
<RateController hz="1.0"> | ||
<RecoveryNode number_of_retries="4" name="ComputePathToPose"> | ||
<ComputePathToPose goal="{goal}" path="{path}" planner_id="GridBased"/> | ||
<RoundRobin name="GlobalPlannerRecoveryActions"> | ||
<ClearEntireCostmap service_name="global_costmap/clear_entirely_global_costmap"/> | ||
<Wait wait_duration="2"/> | ||
</RoundRobin> | ||
</RecoveryNode> | ||
</RateController> | ||
<RecoveryNode number_of_retries="4" name="FollowPath"> | ||
<FollowPath path="{path}" controller_id="FollowPath"/> | ||
<RoundRobin name="PlannerRecoveryActions"> | ||
<ClearEntireCostmap service_name="local_costmap/clear_entirely_local_costmap"/> | ||
<Spin spin_dist="1.57"/> | ||
</RoundRobin> | ||
</RecoveryNode> | ||
</PipelineSequence> | ||
<Wait wait_duration="5"/> | ||
</RecoveryNode> | ||
</BehaviorTree> | ||
</root> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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