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

Skip to content

Commit 6e5f530

Browse files
committed
more docs
1 parent 5de3073 commit 6e5f530

File tree

7 files changed

+159
-11
lines changed

7 files changed

+159
-11
lines changed

docs/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Getting started
22

33
__BehaviorTree.CPP__ is a C++ library that can be easily integrated into
4-
your favourite distributed middleware, such as __ROS__ of __SmartSoft__.
4+
your favourite distributed middleware, such as __ROS__ or __SmartSoft__.
55

66
You can also statically link it into your application (for example a game).
77

docs/tutorial_A_create_trees.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private:
8787

8888
```
8989

90-
We can build a __SimpleActionNode__ from any of these functors:
90+
We can build a `SimpleActionNode` from any of these functors:
9191

9292
- SayHello()
9393
- GripperInterface::open()
@@ -142,7 +142,6 @@ Give the following XML stored in the file __my_tree.xml__
142142

143143
``` XML
144144
<root main_tree_to_execute = "MainTree" >
145-
146145
<BehaviorTree ID="MainTree">
147146
<Sequence name="root_sequence">
148147
<SayHello name="action_hello"/>
@@ -151,19 +150,36 @@ Give the following XML stored in the file __my_tree.xml__
151150
<CloseGripper name="close_gripper"/>
152151
</Sequence>
153152
</BehaviorTree>
153+
</root>
154+
```
154155

156+
Note that the following syntax is also valid:
157+
158+
``` XML
159+
<root main_tree_to_execute = "MainTree" >
160+
<BehaviorTree ID="MainTree">
161+
<Sequence name="root_sequence">
162+
<Action ID="SayHello" name="action_hello"/>
163+
<Action ID="OpenGripper" name="open_gripper"/>
164+
<Action ID="ApproachObject" name="approach_object"/>
165+
<Action ID="CloseGripper" name="close_gripper"/>
166+
</Sequence>
167+
</BehaviorTree>
155168
</root>
156169
```
157170

158-
We must first register our custom TreeNodes into the __BehaviorTreeFactory__
171+
We must first register our custom TreeNodes into the `BehaviorTreeFactory`
159172
and then load the XML from file or text.
160173

161-
The names used in the XML must conincide with those used to register
174+
The identifier used in the XML must coincide with those used to register
162175
the TreeNodes.
163176

164177
The attribute "name" represent the name of the instance and it is optional.
165178

179+
166180
``` c++
181+
#include "behavior_tree_core/xml_parsing.h"
182+
#include "Blackboard/blackboard_local.h"
167183
#include "dummy_nodes.h"
168184

169185
int main()

docs/tutorial_D_subtrees.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

docs/tutorial_E_plugins.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Plugins
2+
3+
In the previous examples we linked the user-defined nodes where included
4+
and linked statically into out projects.
5+
6+
We used the `BehaviorTreeFactory` to registed manualy these custom TreeNodes.
7+
8+
We can avoid these steps loading user-defined TreeNodes at run-time using
9+
pre-compiled dynamic shared libraries, i.e. __plugins__.
10+
11+
# Example
12+
13+
Let's consider the [first tutorial](tutorial_A_create_trees.md).
14+
15+
We can encapsulate the registration of multiple TreeNodes into a single
16+
function like this:
17+
18+
``` c++
19+
BT_REGISTER_NODES(factory)
20+
{
21+
static GripperInterface gi; // we can't have more than instance
22+
23+
factory.registerSimpleAction("SayHello", std::bind(SayHello) );
24+
factory.registerSimpleAction("OpenGripper",
25+
std::bind( &GripperInterface::open, &gi));
26+
factory.registerSimpleAction("CloseGripper",
27+
std::bind( &GripperInterface::close, &gi));
28+
factory.registerNodeType<ApproachObject>("ApproachObject");
29+
factory.registerNodeType<SaySomething>("SaySomething");
30+
}
31+
```
32+
33+
34+
`BT_REGISTER_NODES` is a macro that defines a function which symbol can be loaded
35+
from a dynamic library.
36+
37+
!!! note
38+
This function must be placed in __.cpp__ file, not an header file.
39+
40+
In this particular example we assume that BT_REGISTER_NODES and
41+
the definitions of our custom TreeNodes are defined in the file __dummy_nodes.cpp__.
42+
43+
In __cmake__ the plugin can be compiled using the argument SHARED in
44+
`add_library`.
45+
46+
```cmake
47+
add_library(dummy_nodes SHARED dummy_nodes.cpp )
48+
```
49+
50+
In Linux the file __libdummy_nodes.so__ is created.
51+
52+
Our first tutorial is, as a result, much simpler now:
53+
54+
55+
```c++ hl_lines="3 24"
56+
#include "behavior_tree_core/xml_parsing.h"
57+
#include "Blackboard/blackboard_local.h"
58+
// #include "dummy_nodes.h" YOU DON'T NEED THIS ANYMORE
59+
60+
using namespace BT;
61+
62+
const std::string xml_text = R"(
63+
<root main_tree_to_execute = "MainTree" >
64+
<BehaviorTree ID="MainTree">
65+
<Sequence name="root_sequence">
66+
<SayHello name="action_hello"/>
67+
<OpenGripper name="open_gripper"/>
68+
<ApproachObject name="approach_object"/>
69+
<CloseGripper name="close_gripper"/>
70+
</Sequence>
71+
</BehaviorTree>
72+
</root>
73+
)";
74+
75+
int main()
76+
{
77+
using namespace BT;
78+
BehaviorTreeFactory factory;
79+
factory.registerFromPlugin("./libdummy_nodes.so");
80+
81+
auto tree = buildTreeFromText(factory, xml_text);
82+
83+
tree.root_node->executeTick();
84+
return 0;
85+
}
86+
/* Expected output:
87+
88+
Robot says: "Hello!!!"
89+
GripperInterface::open
90+
ApproachObject: approach_object
91+
GripperInterface::close
92+
*/
93+
94+
```
95+
96+
## Display the manifest of a plugin
97+
98+
BehaviorTree.CPP provides a command line tool called
99+
__bt_plugin_manifest__; it shows all user-defind TreeNodes
100+
registered into the plugin and their corresponding NodeParameters.
101+
102+
103+
```
104+
$> ./bt_plugin_manifest ./libdummy_nodes.so
105+
106+
---------------
107+
ApproachObject [Action]
108+
NodeParameters: 0
109+
---------------
110+
CloseGripper [Action]
111+
NodeParameters: 0
112+
---------------
113+
OpenGripper [Action]
114+
NodeParameters: 0
115+
---------------
116+
SayHello [Action]
117+
NodeParameters: 0
118+
---------------
119+
SaySomething [Action]
120+
NodeParameters: 1:
121+
- [Key]: "message" / [Default]: ""
122+
```
123+
124+
125+
126+
127+
128+

docs/tutorial_F_loggers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

mkdocs.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ pages:
3535
- Sequence Nodes: SequenceNode.md
3636
- Fallback Nodes: FallbackNode.md
3737
- Decorators Nodes: DecoratorNode.md
38-
- The BlackBoard: BlackBoard.md
39-
- Getting Started:
38+
- Tutorials:
4039
- Main concepts: getting_started.md
41-
- How to create a Tree: tutorial_A_create_trees.md
40+
- Create a Tree: tutorial_A_create_trees.md
4241
- Add NodeParameters: tutorial_B_node_parameters.md
43-
- Blackboards: tutorial_C_blackboard.md
42+
- Use Blackboards: tutorial_C_blackboard.md
43+
- Compose with Subtrees: tutorial_D_subtrees.md
44+
- Create Plugins : tutorial_E_plugins.md
45+
- Log state transitions: tutorial_F_loggers.md
4446

tools/bt_plugin_manifest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ int main(int argc, char* argv[])
4343

4444
for( auto& param: params)
4545
{
46-
std::cout << " - [Key]: " << param.first << " / Default value: "
47-
<< param.second << std::endl;
46+
std::cout << " - [Key]: \"" << param.first << "\" / [Default]: \""
47+
<< param.second << "\"" << std::endl;
4848
}
4949

5050
}

0 commit comments

Comments
 (0)