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

Skip to content

Commit 77cd7f3

Browse files
committed
updated documentation
1 parent 28cd91a commit 77cd7f3

File tree

4 files changed

+208
-24
lines changed

4 files changed

+208
-24
lines changed

docs/getting_started.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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

8-
There are some main concepts that you need to understand first.
8+
There are some main concepts that you need to understand first.
99

1010
## Nodes vs Trees
1111

@@ -39,9 +39,9 @@ class __ActionNodeBase__.
3939
Alternatively, we provided a mechanism to create a TreeNode passing a
4040
__function pointer__ to a wrapper (dependency injection).
4141

42-
This approach reduces the amount of boilerplate in your code but has also
43-
some limitations; the most important one is that TreeNodes created using
44-
function pointers can not support [NodeParameters](NodeParameters.md).
42+
This approach reduces the amount of boilerplate in your code; as a reference
43+
please look at the [first tutorial](tutorial_A_create_trees.md) amd the one
44+
describing [non intrusive integration with legacy code](tutorial_g_legacy.md).
4545

4646
## NodeParameters
4747

@@ -57,3 +57,12 @@ This is not surprising, since NodeParameters are usually parsed from file.
5757
The library provides some methods and utility functions to correctly convert
5858
values from string to the desired C++ type.
5959

60+
## Load trees at run-time using the XML format
61+
62+
Despite the fact that the library is written in C++, trees themselves
63+
can be composed at run-time, reading the tree structure from file.
64+
65+
An XML format is descibed in details [here](xml_format.md).
66+
67+
68+

docs/tutorial_A_create_trees.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ int main()
149149

150150
Give the following XML stored in the file __my_tree.xml__
151151

152+
Note that the following syntax is also valid:
153+
152154
``` XML
153155
<root main_tree_to_execute = "MainTree" >
154156
<BehaviorTree ID="MainTree">
@@ -159,30 +161,12 @@ Give the following XML stored in the file __my_tree.xml__
159161
<CloseGripper name="close_gripper"/>
160162
</Sequence>
161163
</BehaviorTree>
162-
163-
<TreeNodesModel>
164-
<Action ID="SayHello"/>
165-
<Action ID="OpenGripper"/>
166-
<Action ID="ApproachObject"/>
167-
<Action ID="CloseGripper"/>
168-
</TreeNodesModel>
169164
</root>
170165
```
171166

172-
Note that the following syntax is also valid:
167+
!!! Note
168+
You can find more details about the XML schema [here](xml_format.md).
173169

174-
``` XML
175-
<root main_tree_to_execute = "MainTree" >
176-
<BehaviorTree ID="MainTree">
177-
<Sequence name="root_sequence">
178-
<Action ID="SayHello" name="action_hello"/>
179-
<Action ID="OpenGripper" name="open_gripper"/>
180-
<Action ID="ApproachObject" name="approach_object"/>
181-
<Action ID="CloseGripper" name="close_gripper"/>
182-
</Sequence>
183-
</BehaviorTree>
184-
</root>
185-
```
186170

187171
We must first register our custom TreeNodes into the `BehaviorTreeFactory`
188172
and then load the XML from file or text.

docs/xml_format.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
2+
## Basics of the XML schema
3+
4+
In the [first tutorial](tutorial_A_create_trees.md) this simple tree
5+
was presented.
6+
7+
``` XML
8+
<root main_tree_to_execute = "MainTree" >
9+
<BehaviorTree ID="MainTree">
10+
<Sequence name="root_sequence">
11+
<SaySomething name="action_hello" message="Hello"/>
12+
<OpenGripper name="open_gripper"/>
13+
<ApproachObject name="approach_object"/>
14+
<CloseGripper name="close_gripper"/>
15+
</Sequence>
16+
</BehaviorTree>
17+
</root>
18+
```
19+
20+
You may notice that:
21+
22+
- The first tag of the tree is `<root>`. It should contain 1 or more tags `<BehaviorTree>`.
23+
24+
- The tag `<BehaviorTree>` should have the attribute `[ID]`.
25+
26+
27+
- The tag `<root>` should contain the attribute `[main_tree_to_execute]`,refering the ID of the main tree.
28+
29+
- The attribute `[main_tree_to_execute]` is mandatory if the file contains multiple `<BehaviorTree>`,
30+
optional otherwise.
31+
32+
- Each TreeNode is represented by a single tag. In particular:
33+
34+
- The name of the tag is the __ID__ used to register the TreeNode in the factory.
35+
- The attribute `[name]` refers to the name of the instance and is __optional__.
36+
- Nodeparameters are passed as attribute as well. In the previous example, the action
37+
`SaySomething` requires the NodeParameter `message`.
38+
39+
- In terms of number of children:
40+
41+
- `ControlNodes` contain __1 to N children__.
42+
- `DecoratorNodes` and Subtrees contain __only 1 child__.
43+
- `ActionNodes` and `ConditionNodes` have __no child__.
44+
45+
46+
## Compact vs Explicit representation
47+
48+
The following two syntaxes are both valid:
49+
50+
``` XML
51+
<SaySomething name="action_hello" message="Hello World"/>
52+
<Action ID="SaySomething" name="action_hello" message="Hello World"/>
53+
```
54+
55+
We will call the former syntax "__compact__" and the latter "__explicit__".
56+
The first example represented with the explicit syntax would become:
57+
58+
``` XML
59+
<root main_tree_to_execute = "MainTree" >
60+
<BehaviorTree ID="MainTree">
61+
<Sequence name="root_sequence">
62+
<Action ID="SaySomething" name="action_hello" message="Hello"/>
63+
<Action ID="OpenGripper" name="open_gripper"/>
64+
<Action ID="ApproachObject" name="approach_object"/>
65+
<Action ID="CloseGripper" name="close_gripper"/>
66+
</Sequence>
67+
</BehaviorTree>
68+
</root>
69+
```
70+
71+
Even if the compact syntax is more convenient and easier to write, it provides
72+
too little information about the model of the TreeNode. Tools like __Groot__ require either
73+
the _explicit_ syntax or additional information.
74+
This information can be added using the tag `<TreeNodeModel>`.
75+
76+
To make the compact version of our tree compatible with Groot, the XML must be modified as follows:
77+
78+
79+
``` XML
80+
<root main_tree_to_execute = "MainTree" >
81+
<BehaviorTree ID="MainTree">
82+
<Sequence name="root_sequence">
83+
<SaySomething name="action_hello" message="Hello"/>
84+
<OpenGripper name="open_gripper"/>
85+
<ApproachObject name="approach_object"/>
86+
<CloseGripper name="close_gripper"/>
87+
</Sequence>
88+
</BehaviorTree>
89+
90+
<!-- the BT executor don't require this, but Groot does -->
91+
<TreeNodeModel>
92+
<Action ID="SaySomething" message="default message"/>
93+
<Action ID="OpenGripper"/>
94+
<Action ID="ApproachObject"/>
95+
<Action ID="CloseGripper"/>
96+
</TreeNodeModel>
97+
</root>
98+
```
99+
100+
## Subtrees
101+
102+
As we saw in [this tutorial](tutorial_D_subtrees.md), it is possible to include
103+
a Subtree inside another tree to avoid "copy and pasting" the same tree in
104+
multiple location and to reduce complexity.
105+
106+
Let's say that we want to incapsulate few action into the behaviorTree "__GraspObject__"
107+
(being optional, attributes [name] are omitted for simplicity).
108+
109+
``` XML hl_lines="6"
110+
<root main_tree_to_execute = "MainTree" >
111+
112+
<BehaviorTree ID="MainTree">
113+
<Sequence>
114+
<Action ID="SaySomething" message="Hello World"/>
115+
<Subtree ID="GraspObject"/>
116+
</Sequence>
117+
</BehaviorTree>
118+
119+
<BehaviorTree ID="GraspObject">
120+
<Sequence>
121+
<Action ID="OpenGripper"/>
122+
<Action ID="ApproachObject"/>
123+
<Action ID="CloseGripper"/>
124+
</Sequence>
125+
</BehaviorTree>
126+
</root>
127+
```
128+
129+
We may notice as the entire tree "GraspObject" is executed after "SaySomething".
130+
131+
## Include external files
132+
133+
__Since version 2.4__.
134+
135+
You can include external files in a way that is similar to __#include <file>__ in C++.
136+
We can do this easily using the tag:
137+
138+
``` XML
139+
<include path="relative_or_absolute_path_to_file">
140+
```
141+
142+
using the previous example, we may split the two behavior trees into two files:
143+
144+
145+
``` XML hl_lines="5"
146+
<!-- file maintree.xml -->
147+
148+
<root main_tree_to_execute = "MainTree" >
149+
150+
<include path="grasp.xml"/>
151+
152+
<BehaviorTree ID="MainTree">
153+
<Sequence>
154+
<Action ID="SaySomething" message="Hello World"/>
155+
<Subtree ID="GraspObject"/>
156+
</Sequence>
157+
</BehaviorTree>
158+
</root>
159+
```
160+
161+
``` XML
162+
<!-- file grasp.xml -->
163+
164+
<root main_tree_to_execute = "GraspObject" >
165+
<BehaviorTree ID="GraspObject">
166+
<Sequence>
167+
<Action ID="OpenGripper"/>
168+
<Action ID="ApproachObject"/>
169+
<Action ID="CloseGripper"/>
170+
</Sequence>
171+
</BehaviorTree>
172+
</root>
173+
```
174+
175+
!!! Note "Note for ROS users"
176+
If you want to find a file inside a [ROS package](http://wiki.ros.org/Packages),
177+
you can use this syntax:
178+
179+
`<include ros_pkg="name_package" path="path_relative_to_pkg/grasp.xml"/>`
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ pages:
4444
- "Tutorial 5: Plugins": tutorial_E_plugins.md
4545
- "Tutorial 6: Loggers": tutorial_F_loggers.md
4646
- "Tutorial 7: Legacy code": tutorial_G_legacy.md
47+
- "the XML format": xml_format.md
4748

0 commit comments

Comments
 (0)