Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210910794
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210910794
Commits
2a805a8a
Commit
2a805a8a
authored
5 years ago
by
Steven Macenski
Browse files
Options
Downloads
Patches
Plain Diff
port plugin control
parent
9b745337
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nav2_behavior_tree/plugins/control/recovery_node.cpp
+160
-0
160 additions, 0 deletions
nav2_behavior_tree/plugins/control/recovery_node.cpp
with
160 additions
and
0 deletions
nav2_behavior_tree/plugins/control/recovery_node.cpp
0 → 100644
+
160
−
0
View file @
2a805a8a
// 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.
#ifndef NAV2_BEHAVIOR_TREE__RECOVERY_NODE_HPP_
#define NAV2_BEHAVIOR_TREE__RECOVERY_NODE_HPP_
#include
<string>
#include
"behaviortree_cpp_v3/control_node.h"
namespace
nav2_behavior_tree
{
/**
* @brief The RecoveryNode has only two children and returns SUCCESS if and only if the first child
* returns SUCCESS.
*
* - If the first child returns FAILURE, the second child will be executed. After that the first
* child is executed again if the second child returns SUCCESS.
*
* - If the first or second child returns RUNNING, this node returns RUNNING.
*
* - If the second child returns FAILURE, this control node will stop the loop and returns FAILURE.
*
*/
class
RecoveryNode
:
public
BT
::
ControlNode
{
public:
RecoveryNode
(
const
std
::
string
&
name
,
const
BT
::
NodeConfiguration
&
conf
)
:
BT
::
ControlNode
::
ControlNode
(
name
,
conf
),
current_child_idx_
(
0
),
retry_count_
(
0
)
{
getInput
(
"number_of_retries"
,
number_of_retries_
);
};
~
RecoveryNode
()
override
=
default
;
// Any BT node that accepts parameters must provide a requiredNodeParameters method
static
BT
::
PortsList
providedPorts
()
{
return
{
BT
::
InputPort
<
int
>
(
"number_of_retries"
,
1
,
"Number of retries"
)
};
}
private
:
unsigned
int
current_child_idx_
;
unsigned
int
number_of_retries_
;
unsigned
int
retry_count_
;
BT
::
NodeStatus
tick
()
override
{
const
unsigned
children_count
=
children_nodes_
.
size
();
if
(
children_count
!=
2
)
{
throw
BT
::
BehaviorTreeException
(
"Recovery Node '"
+
name
()
+
"' must only have 2 children."
);
}
setStatus
(
BT
::
NodeStatus
::
RUNNING
);
while
(
current_child_idx_
<
children_count
&&
retry_count_
<
number_of_retries_
)
{
TreeNode
*
child_node
=
children_nodes_
[
current_child_idx_
];
const
BT
::
NodeStatus
child_status
=
child_node
->
executeTick
();
if
(
current_child_idx_
==
0
)
{
switch
(
child_status
)
{
case
BT
::
NodeStatus
::
SUCCESS
:
{
retry_count_
=
0
;
halt
();
return
BT
::
NodeStatus
::
SUCCESS
;
}
break
;
case
BT
::
NodeStatus
::
FAILURE
:
{
// tick second child
if
(
retry_count_
<=
number_of_retries_
)
{
current_child_idx_
++
;
break
;
}
else
{
haltChildren
(
0
);
return
BT
::
NodeStatus
::
FAILURE
;
}
}
break
;
case
BT
::
NodeStatus
::
RUNNING
:
{
return
BT
::
NodeStatus
::
RUNNING
;
}
break
;
default
:
{
}
}
// end switch
}
else
if
(
current_child_idx_
==
1
)
{
switch
(
child_status
)
{
case
BT
::
NodeStatus
::
SUCCESS
:
{
retry_count_
++
;
current_child_idx_
--
;
haltChildren
(
1
);
}
break
;
case
BT
::
NodeStatus
::
FAILURE
:
{
current_child_idx_
--
;
retry_count_
=
0
;
halt
();
return
BT
::
NodeStatus
::
FAILURE
;
}
break
;
case
BT
::
NodeStatus
::
RUNNING
:
{
return
BT
::
NodeStatus
::
RUNNING
;
}
break
;
default
:
{
}
}
// end switch
}
}
// end while loop
retry_count_
=
0
;
halt
();
return
BT
::
NodeStatus
::
FAILURE
;
};
void
RecoveryNode
::
halt
()
override
{
ControlNode
::
halt
();
current_child_idx_
=
0
;
retry_count_
=
0
;
};
};
}
// namespace nav2_behavior_tree
#include
"behaviortree_cpp_v3/bt_factory.h"
BT_REGISTER_NODES
(
factory
)
{
factory
.
registerNodeType
<
nav2_behavior_tree
::
RecoveryNode
>
(
"RecoveryNode"
);
}
#endif // NAV2_BEHAVIOR_TREE__RECOVERY_NODE_HPP_
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment