Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 654177a

Browse files
author
Davide Faconti
committed
more docs
1 parent 6e5f530 commit 654177a

File tree

7 files changed

+413
-54
lines changed

7 files changed

+413
-54
lines changed

docs/images/CrossDoorSubtree.png

20.8 KB
Loading

docs/tutorial_A_create_trees.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the former for the sake of completeness.
1010

1111
## How to create your own ActionNodes
1212

13-
You can find the source code here: [dummy_nodes.h](../sample_nodes/ dummy_nodes.h)
13+
You can find the source code here: [dummy_nodes.h](../sample_nodes/dummy_nodes.h)
1414

1515
The default (and recommended) way to create a TreeNode is by inheritance.
1616

@@ -93,9 +93,7 @@ We can build a `SimpleActionNode` from any of these functors:
9393
- GripperInterface::open()
9494
- GripperInterface::close()
9595

96-
97-
## Tutorial 01: a statically created Tree
98-
96+
## A static Tree
9997

10098
``` c++
10199
#include "dummy_nodes.h"
@@ -136,7 +134,7 @@ int main()
136134

137135
```
138136

139-
## Tutorial 02: a dynamically created Tree
137+
## A dynamically created Tree
140138

141139
Give the following XML stored in the file __my_tree.xml__
142140

docs/tutorial_B_node_parameters.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,24 @@ Please note:
3737
- The __static__ method `requiredNodeParameters()` contains a single key/value pair.
3838
The string "default message" is the default value.
3939

40-
- Parameters MUST be accessed using the method __getParam()__.
40+
- Parameters MUST be accessed using the method `getParam()`, preferably in the
41+
`tick()` method, since this value may change over time.
4142

42-
``` c++ hl_lines="4 10 22"
43+
``` c++ hl_lines="5 9 18"
4344
class SaySomething: public ActionNodeBase
4445
{
4546
public:
47+
// There must be a constructor with this signature
4648
SaySomething(const std::string& name, const NodeParameters& params):
4749
ActionNodeBase(name, params) {}
4850

51+
// It is mandatory to define this static method.
52+
static const NodeParameters& requiredNodeParameters()
53+
{
54+
static NodeParameters params = {{"message","default message"}};
55+
return params;
56+
}
57+
4958
virtual NodeStatus tick() override
5059
{
5160
std::string msg;
@@ -57,15 +66,7 @@ public:
5766
std::cout << "Robot says: " << msg << std::endl;
5867
return BT::NodeStatus::SUCCESS;
5968
}
60-
6169
virtual void halt() override {}
62-
63-
// It is mandatory to define this static method.
64-
static const NodeParameters& requiredNodeParameters()
65-
{
66-
static NodeParameters params = {{"message","default message"}};
67-
return params;
68-
}
6970
};
7071
```
7172

@@ -83,19 +84,21 @@ struct Pose2D
8384

8485
If we want the method `getParam()` to be able to parse a string
8586
and store its value into a Pose2D, we must provide our own specialization
86-
of `convertFromString<>()`.
87+
of `convertFromString<T>()`.
8788

8889
In this case, we want to represent Pose2D as three real numbers separated by
8990
semicolons.
9091

91-
``` c++ hl_lines="5"
92+
``` c++ hl_lines="6"
93+
// use this namespace
9294
namespace BT{
9395

9496
// This template specialization is needed if you want
9597
// to AUTOMATICALLY convert a NodeParameter into a Pose2D
96-
template <> Pose2D convertFromString(const std::string& key)
98+
template <> Pose2D BT::convertFromString(const std::string& key)
9799
{
98-
// Three real numbers separated by semicolons
100+
// Three real numbers separated by semicolons.
101+
// You may use <boost/algorithm/string/split.hpp> if you prefer
99102
auto parts = BT::splitString(key, ';');
100103
if( parts.size() != 3)
101104
{
@@ -109,9 +112,11 @@ template <> Pose2D convertFromString(const std::string& key)
109112
return output;
110113
}
111114
}
115+
116+
} // end naespace
112117
```
113118

114-
We now define a synchronous ActionNode called __MoveBaseAction__.
119+
We now define a __asynchronous__ ActionNode called __MoveBaseAction__.
115120

116121
The method `getParam()` will call the function `convertFromString<Pose2D>()` under the hood;
117122
alternatively, we can use the latter directly, for instance to convert the default
@@ -139,7 +144,7 @@ public:
139144
Pose2D goal;
140145
if( getParam<Pose2D>("goal", goal) == false )
141146
{
142-
auto default_goal_value = requiredNodeParameters().at("goal");
147+
auto default_goal = requiredNodeParameters().at("goal");
143148
goal = BT::convertFromString<Pose2D>( default_goal_value );
144149
}
145150
@@ -149,14 +154,15 @@ public:
149154
halt_requested_ = false;
150155
151156
int count = 0;
152-
// "compute" for 250 milliseconds or until halt_requested_ is true
157+
// "compute" for 250 milliseconds or until halt_requested_
153158
while( !halt_requested_ && count++ < 25)
154159
{
155160
SleepMilliseconds(10);
156161
}
157162

158163
std::cout << "[ MoveBase: FINISHED ]" << std::endl;
159-
return halt_requested_ ? NodeStatus::SUCCESS : NodeStatus::SUCCESS;
164+
return halt_requested_ ? NodeStatus::FAILURE :
165+
NodeStatus::SUCCESS;
160166
}
161167

162168
virtual void halt() override

docs/tutorial_D_subtrees.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
11

2+
3+
One of the main advantages of Behavior Trees is that they are __intrinsically
4+
hierarchical__.
5+
6+
You might have noticed that it is always possible to raise the level of
7+
abstraction looking one node up in the hierarchy of the tree.
8+
9+
For example, in the [Introduction](BT_basics.md) page we have seen this tree:
10+
11+
![FallbackNodes](images/FallbackBasic.png)
12+
13+
The Sequence calle "Unlock" can be seen as an entire subtree with an arbitrary
14+
level of complexity.
15+
16+
BehaviorTree.CPP provides a way to create reusable and composable Subtrees
17+
that can be included as nodes of a larger and more complex tree.
18+
19+
## Example: subtrees in XML
20+
21+
To use the Subtree funtionality, you __don't__ need to modify your
22+
__cpp__ code, nor your existing TreeNodes.
23+
24+
Multiple BehaviorTrees can be created and composed in the XML itself.
25+
26+
27+
``` XML hl_lines="21"
28+
<root main_tree_to_execute = "MainTree">
29+
<!--------------------------------------->
30+
<BehaviorTree ID="DoorClosed">
31+
<Sequence name="door_closed_sequence">
32+
<Negation>
33+
<IsDoorOpen/>
34+
</Negation>
35+
<RetryUntilSuccesful num_attempts="4">
36+
<OpenDoor/>
37+
</RetryUntilSuccesful>
38+
<PassThroughDoor/>
39+
</Sequence>
40+
</BehaviorTree>
41+
<!--------------------------------------->
42+
<BehaviorTree ID="MainTree">
43+
<Fallback name="root_Fallback">
44+
<Sequence name="door_open_sequence">
45+
<IsDoorOpen/>
46+
<PassThroughDoor/>
47+
</Sequence>
48+
<SubTree ID="DoorClosed"/>
49+
<PassThroughWindow/>
50+
</Fallback>
51+
</BehaviorTree>
52+
<!--------------------------------------->
53+
</root>
54+
```
55+
56+
The corresponding graphical representation is:
57+
58+
![CrossDoorSubtree](images/CrossDoorSubtree.png)
59+

0 commit comments

Comments
 (0)