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

Skip to content

Commit 2a2c34c

Browse files
author
Davide Faconti
committed
[DOCS]: some updates and typos fixed
1 parent 09651af commit 2a2c34c

File tree

7 files changed

+105
-89
lines changed

7 files changed

+105
-89
lines changed

docs/BT_basics.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ For instance, in a service-oriented architecture, the leaves would contain
1111
the "client" code that communicate with the "server" that performs the
1212
operation.
1313

14-
![Leaf To Component Communication](images/LeafToComponentCommunication.png)
14+
In the following example, we can see two Actions executed in a sequence,
15+
`DetectObject` and `GraspObject`.
1516

17+
![Leaf To Component Communication](images/LeafToComponentCommunication.png)
1618

17-
The other nodes of the tree, those which are not leaves, control the
19+
The other nodes of the tree, those which are __not leaves__, control the
1820
"flow of execution".
1921

20-
To better understand how this flow takes place , imagine a signal, that we will further
21-
call "__tick__"; it is executed at the __root__ of the tree and propagates through
22-
the branches until it reaches one or multiple leaves.
22+
To better understand how this control flow takes place , imagine a signal
23+
called "__tick__"; it is executed at the __root__ of the tree and it propagates
24+
through the branches until it reaches one or multiple leaves.
25+
26+
!!! Note
27+
The word __tick__ will be often used as a *verb* (to tick / to be ticked) and it means
28+
29+
"To invoke the callback `tick()` called of a `TreeNode`".
2330

24-
The `tick()` callback returns a `NodeStatus` that will be either:
31+
Then a `TreeNode` is ticked, it returns a `NodeStatus` that can be either:
2532

2633
- __SUCCESS__
2734
- __FAILURE__
@@ -37,7 +44,7 @@ and they needs more time to return a valid result.
3744
This C++ library provides also the status __IDLE__; it means that the node is ready to
3845
start.
3946

40-
The result of a node is propagated back to the parent, that will decide
47+
The result of a node is propagated back to its parent, that will decide
4148
which child should be ticked next or will return a result to its own parent.
4249

4350
## Types of nodes
@@ -57,7 +64,7 @@ alter the state of the system.
5764
![UML hierarchy](images/TypeHierarchy.png)
5865

5966

60-
## Learn by example
67+
## Examples
6168

6269
To better understand how a BehaviorTrees work, let's focus on some practical
6370
examples. For the sake of simplicity we will not take into account what happens
@@ -83,11 +90,11 @@ In short:
8390

8491
- If a child returns SUCCESS, tick the next one.
8592
- If a child returns FAILURE, then no more children are ticked and the Sequence returns FAILURE.
86-
- If all the children return SUCCESS, then the Sequence returns SUCCESS too.
93+
- If __all__ the children return SUCCESS, then the Sequence returns SUCCESS too.
8794

88-
??? warning "Exercise: find the bug! Expand to read the answer."
95+
!!! warning "Have you spotted the bug?"
8996
If the action __GrabBeer__ fails, the door of the
90-
fridge would remain open, since the last action __CloseDoor__ is skipped.
97+
fridge would remain open, since the last action __CloseFridge__ is skipped.
9198

9299

93100
### Decorators
@@ -113,14 +120,15 @@ __Apparently__, the branch on the right side means:
113120

114121
If the door is closed, then try to open it.
115122
Try up to 3 times, otherwise give up and return FAILURE.
116-
117-
118-
__But__ there is an error. Can you find it?
119123

120-
??? warning "Exercise: find the bug! Expand to read the answer."
124+
But...
125+
126+
!!! warning "Have you spotted the bug?"
121127
If __DoorOpen__ returns FAILURE, we have the desired behaviour.
122128
But if it returns SUCCESS, the left branch fails and the entire Sequence
123-
is interrupted.
129+
is interrupted.
130+
131+
We will see later how we can improve this tree.
124132

125133

126134
### Second ControlNode: Fallback
@@ -140,37 +148,37 @@ In the next example, you can see how Sequence and Fallbacks can be combined:
140148
![FallbackNodes](images/FallbackBasic.png)
141149

142150

143-
>In the door open?
151+
> Is the door open?
144152
>
145-
> I not, try to open the door.
153+
> If not, try to open the door.
146154
>
147155
> Otherwise, if you have a key, unlock and open the door.
148156
>
149157
> Otherwise, smash the door.
150158
>
151-
>If any of these actions succeeded, then enter the room.
159+
> If __any__ of these actions succeeded, then enter the room.
152160
153161
### "Fetch me a beer" revisited
154162

155-
We can now improve the "Fetch Me a Beer" example, which leaves the door open
156-
if the beer was not there.
163+
We can now improve the "Fetch Me a Beer" example, which left the door open
164+
if the beer was not inside the fridge.
157165

158-
We use the color "green" to represent nodes which will return
166+
We use the color "green" to represent nodes which return
159167
SUCCESS and "red" for those which return FAILURE. Black nodes are never executed.
160168

161169
![FetchBeer failure](images/FetchBeerFails.png)
162170

163-
164171
Let's create an alternative tree that closes the door even when __GrabBeer__
165172
returns FAILURE.
166173

167174

168175
![FetchBeer failure](images/FetchBeer.png)
169176

170-
Both the trees will close the door of the fridge, eventually, but:
177+
Both these trees will close the door of the fridge, eventually, but:
171178

172179
- the tree on the __left__ side will always return SUCCESS if we managed to
173180
open and close the fridge.
181+
174182
- the tree on the __right__ side will return SUCCESS if the beer was there,
175183
FAILURE otherwise.
176184

docs/index.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,37 @@ to visualize, record, replay and analyze state transitions.
2020

2121
![ReadTheDocs](images/ReadTheDocs.png)
2222

23+
## What is a Behavior Tree?
24+
25+
A Behavior Tree (__BT__) is a way to structure the switching between different
26+
tasks in an autonomous agent, such as a robot or a virtual entity in a computer game.
27+
28+
BTs are a very efficient way of creating complex systems that are both modular and reactive.
29+
These properties are crucial in many applications, which has led to the spread
30+
of BT from computer game programming to many branches of AI and Robotics.
31+
32+
If you are already familiar with Finite State Machines (__FSM__), you will
33+
easily grasp most of the concepts but, hopefully, you will find that BTs
34+
are more expressive and easier to reason about.
35+
36+
The main advantages of Behavior Trees, when compared to FSMs are:
37+
38+
- __They are intrinsically Hierarchical__: this means that we can _compose_
39+
complex behaviors including entire trees as sub-branches of a bigger tree.
40+
For instance, the behavior "Fetch Beer" may reuse in one of its nodes the tree
41+
"Grasp Object".
42+
43+
- __Their graphical representation has a semantic meaning__: it is easier to
44+
"read" a BT and understand the corresponding workflow.
45+
State transitions in FSMs, by comparisons, are harder to understand
46+
both in their textual and graphical representation.
47+
48+
- __They are more expressive__: Ready to use ControlNodes and DecoratorNodes
49+
make possible to express more complex control flows. The user can extend the
50+
"vocabulary" with his/her own custom nodes.
51+
2352

24-
## The problem
53+
## "Ok, but WHY do we need BehaviorTrees (or FSM)?"
2554

2655
Many software systems, being robotics a notable example, are inherently
2756
complex.
@@ -59,32 +88,3 @@ __Finite State Machines__ were created specifically with this goal in mind, but
5988
the recent years __Behavior Trees__ gained popularity, especially in the game industry.
6089

6190

62-
## What is a Behavior Tree?
63-
64-
A Behavior Tree (__BT__) is a way to structure the switching between different
65-
tasks in an autonomous agent, such as a robot or a virtual entity in a computer game.
66-
67-
BTs are a very efficient way of creating complex systems that are both modular and reactive.
68-
These properties are crucial in many applications, which has led to the spread
69-
of BT from computer game programming to many branches of AI and Robotics.
70-
71-
If you are already familiar with Finite State Machines (__FSM__), you will
72-
easily grasp most of the concepts but, hopefully, you will find that BTs
73-
are more expressive and easier to reason about.
74-
75-
The main advantages of Behavior Trees, when compared to FSMs are:
76-
77-
- __They are intrinsically Hierarchical__: this means that we can _compose_
78-
complex behaviors including entire trees as sub-branches of a bigger tree.
79-
For instance, the behavior "Fetch Beer" may reuse in one of its nodes the tree
80-
"Grasp Object".
81-
82-
- __Their graphical representation has a semantic meaning__: it is easier to
83-
"read" a BT and understand the corresponding workflow.
84-
State transitions in FSMs, by comparisons, are harder to understand
85-
both in their textual and graphical representation.
86-
87-
- __They are more expressive__: Ready to use ControlNodes and DecoratorNodes
88-
make possible to express more complex control flows. The user can extend the
89-
"vocabulary" with his/her own custom nodes.
90-

docs/tutorial_A_create_trees.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ As you can see:
4545
- The method __tick()__ is the place where the actual Action takes place.
4646
It must return a NodeStatus, i.e. RUNNING, SUCCESS or FAILURE.
4747

48-
- The method __halt()__ is used to stop an asynchronous Action. ApproachObject
48+
- The method __halt()__ is used to stop an __asynchronous Action__. ApproachObject
4949
doesn't need it.
5050

51-
5251
Alternatively, we can use __dependecy injection__ to create a TreeNode given
5352
a function pointer.
5453

@@ -184,7 +183,7 @@ We must first register our custom TreeNodes into the `BehaviorTreeFactory`
184183
The identifier used in the XML must coincide with those used to register
185184
the TreeNodes.
186185

187-
The attribute "name" represent the name of the instance and it is optional.
186+
The attribute "name" represents the name of the instance and it is optional.
188187

189188

190189
``` c++

docs/tutorial_B_node_parameters.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Please note:
3535
- The __static__ method `requiredNodeParameters()` contains a single key/value pair.
3636
The string "default message" is the default value.
3737

38-
- Parameters must be accessed using the method `getParam()`, preferably in the
38+
- Parameters must be accessed using the method `getParam()`, preferably inside the
3939
`tick()` method.
4040

4141
``` c++ hl_lines="5 9 18"
@@ -81,11 +81,16 @@ struct Pose2D
8181
```
8282

8383
If we want the method `getParam()` to be able to parse a string
84-
and store its value into a Pose2D, we must provide our own specialization
84+
and store its value into a `Pose2D`, we must provide our own template specialization
8585
of `convertFromString<T>()`.
8686

87-
In this case, we want to represent Pose2D as three real numbers separated by
88-
semicolons.
87+
In this case, the text representation of a `Pose2D` is three real numbers separated by
88+
semicolons, like this:
89+
90+
"1.1;-2.32;0.4"
91+
92+
Since this is a common pattern, the library provide the helper function `BT::splitString`.
93+
8994

9095
``` c++ hl_lines="6"
9196
// use this namespace
@@ -111,13 +116,15 @@ template <> Pose2D BT::convertFromString(const std::string& key)
111116
}
112117
}
113118

114-
} // end naespace
119+
} // end namespace
115120
```
116121

117122
We now define a __asynchronous__ ActionNode called __MoveBaseAction__.
118123

124+
The method tick() of an `ActionNode` is executed in its own thread.
125+
119126
The method `getParam()` will call the function `convertFromString<Pose2D>()` under the hood;
120-
alternatively, we can use the latter directly, for instance to convert the default
127+
alternatively, we can use the latter funtion directly, for instance to convert the default
121128
string "0;0;0" into a Pose2D.
122129

123130
``` c++ hl_lines="20 21 22 23 24"
@@ -175,9 +182,7 @@ private:
175182
176183
## NodeParameters in the XML
177184
178-
179-
To pass the parameter in the XML, use an attribute
180-
with the same name:
185+
To pass the parameter from a XML, use attributes:
181186
182187
``` XML
183188
<Sequence>

docs/tutorial_C_blackboard.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Blackboards
22

3-
The blackboard is a a __key/value__ storage that can be shared by all the Nodes
3+
The blackboard is a a __key/value__ storage shared by all the Nodes
44
of a tree.
55

66
The __key__ is a string whilst the __value__ is a type-erased container (called `SafeAny::Any`)
77
that allows the user to store any C++ object and to cast it back to its original form.
88

9-
Contrariwise to `boost::any` and `std::any`, this container will also try to
9+
Contrariwise to `boost::any` and `std::any`, `SafeAny::Any` will also try to
1010
avoid common overflow and underflow errors.
1111

12-
You can't cast a negative number into an `unsigned integer`,
12+
In fact, you can't cast a negative number into an `unsigned integer`,
1313
nor a very large number that exceeds 2^8 into a `char`.
1414

15-
If the __value__ is stored as a string, it will use `convertFromString<T>()`
15+
If the __value__ is stored as a string, the blackboard will use `convertFromString<T>()`
1616
to cast it to the type T (see [previous example](tutorial_B_node_parameters.md));
1717

1818
The user can create his/her own Blackboards backend; it is possible, for instance,
@@ -61,9 +61,10 @@ Let's consider the following XML tree definition:
6161
The root SequenceStar will execute four actions:
6262

6363
- `CalculateGoalPose` writes into the blackboard key "GoalPose".
64-
- The syntax `${...}` tells to `MoveBase` to read the goal from the key "GoalPose" in the blackboard.
64+
- The syntax `${...}` tells to `MoveBase` to read the goal at run-time from the blackboard;
65+
they blackboard key is "GoalPose".
6566
- Alternatively, you can write a key/value pair into the blackboard using the built-in action `SetBlackboard`.
66-
- Similar to step 2. Pose2D is retrieved from "OtherGoal".
67+
- Similar to step 2. Pose2D is retrieved from the key "OtherGoal".
6768

6869
!!! note
6970
For your information, __GoalPose__ is stored as a type erased Pose2D.

docs/tutorial_E_plugins.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Plugins
22

3-
In the previous examples we linked the user-defined nodes where included
4-
and linked statically into out projects.
3+
In the previous examples the user-defined nodes where included
4+
and linked statically into out C++ projects.
55

66
We used the `BehaviorTreeFactory` to registed manualy these custom TreeNodes.
77

@@ -12,11 +12,13 @@ pre-compiled __dynamic shared libraries, i.e. plugins__.
1212

1313
Let's consider the [first tutorial](tutorial_A_create_trees.md).
1414

15-
To do this we must encapsulate the registration of multiple TreeNodes into a single
16-
function like this:
15+
To create a plugin we must encapsulate the registration of one or multiple TreeNodes
16+
into a single function like this:
1717

1818
``` c++
19-
// This is a macro. Just deal with it.
19+
// This is a macro that defines a function with a single argument
20+
// (BehaviorTreeFactory& factory)
21+
2022
BT_REGISTER_NODES(factory)
2123
{
2224
static GripperInterface gi; // we can't have more than instance
@@ -34,18 +36,18 @@ BT_REGISTER_NODES(factory)
3436
!!! note
3537
This function must be placed in __.cpp__ file, not the header file.
3638
37-
In this particular example we assume that BT_REGISTER_NODES and
39+
Here, we assume that BT_REGISTER_NODES and
3840
the definitions of our custom TreeNodes are all defined in the file __dummy_nodes.cpp__.
3941
40-
If you compile the plugin using __cmake__, add the argument `SHARED` to
42+
When you use __cmake__ to compile a plugin, add the argument `SHARED` to
4143
`add_library`.
4244
4345
```cmake
4446
#your CMakeLists.txt
4547
add_library(dummy_nodes SHARED dummy_nodes.cpp )
4648
```
4749

48-
In Linux the file __libdummy_nodes.so__ will be created.
50+
In Linux, the file __libdummy_nodes.so__ will be created.
4951

5052
The [first tutorial](tutorial_A_create_trees.md) becomes, as a result, much simpler:
5153

0 commit comments

Comments
 (0)