@@ -10,71 +10,76 @@ our coordinating component interacts with the rest of the system.
1010For instance, in a service-oriented architecture, the leaves would contain
1111the "client" code that triggers an action.
1212
13- All the other nodes of the tree, those which are not leaves, control the
13+ The other nodes of the tree, those which are not leaves, control the
1414"flow of execution".
1515
1616To better understand how this flow takes place , imagine a signal, that we will further
1717call "__ tick__ " that is executed at the __ root__ of the tree and propagates through
18- the branches until it reaches a leave .
18+ the branches until it reaches one or multiple leaves .
1919
2020The result of a tick can be either:
2121
2222- __ SUCCESS__
2323- __ FAILURE__
2424- __ RUNNING__
2525
26+
2627The first two, as their names suggest, inform their parent that their operation
2728 was a success or a failure.
28- The latter usually means that the execution of the TreeNode is not completed
29- and it needs more time to return a valid result.
29+
30+ RUNNING is returned by asynchronous nodes when their execution is not completed
31+ and they needs more time to return a valid result.
32+
33+ This C++ library provides also the status __ IDLE__ ; it means that the node is ready to
34+ start.
3035
3136The result of a node is propagated back to the parent, that will decide
32- which child should be ticked next or will return a result itself .
37+ which child should be ticked next or will return a result to its own parent .
3338
3439## Types of nodes
3540
3641__ ControlNodes__ are nodes which can have 1 to N children. Once a tick
3742is received, this tick may be propagated to one or more of the children.
3843
39- __ DecoratorNodes__ can have only a single child.
44+ __ DecoratorNodes__ is similar to the ControlNode, but it can have only a single child.
4045
4146__ ActionNodes__ are leaves and do not have children. The user should implement
42- their own ActionNodes that perform the actual task.
47+ their own ActionNodes to perform the actual task.
4348
44- __ ConditionNodes__ are equivalent to ActionNodes, with the exeption that
45- they are alwais aotmic ( they should not return RUNNING) and they should not
49+ __ ConditionNodes__ are equivalent to ActionNodes, but
50+ they are always atomic, i.e. they must not return RUNNING. They should not
4651alter the state of the system.
4752
4853![ UML hierarchy] ( images/TypeHierarchy.png )
4954
50- !!! note
51- Actions and Conditions differ only in terms of __ semantic__ .
52- From an implementation point of view they are the same.
5355
5456## Learn by example
5557
56- To better understand how a BehaviorTrees work let's focus on some practical
58+ To better understand how a BehaviorTrees work, let's focus on some practical
5759examples. For the sake of simplicity we will not take into account what happens
5860when an action returns RUNNING.
5961
6062We will assume that each Action is executed atomically and synchronously.
61- In future sections we will more thoughtfully analyze asynchronous actions.
63+
6264
6365### Sequence
6466
6567Let's illustrate how a BT works using the most basic and frequently used
6668ControlNode: the [ SequenceNode] ( SequenceNode.md ) .
6769
70+ The children of a ControlNode are always __ ordered__ ; it is up to the ControlNode
71+ to consider this order or not.
72+
73+ In the graphical representation, the order of execution is __ from left to right__ .
74+
6875![ Simple Sequence: fridge] ( images/SequenceBasic.png )
6976
70- It is important to notice that the children of a ControlNode are __ ordered__ .
71- In this case the order of execution is __ from left to right__ .
7277
73- A Sequence works as described next :
78+ In short :
7479
7580- If a child returns SUCCESS, tick the next one.
7681- If a child returns FAILURE, then no more children are ticked and the Sequence returns FAILURE.
77- - If all the children return SUCCESS, then the Fallback returns SUCCESS too.
82+ - If all the children return SUCCESS, then the Sequence returns SUCCESS too.
7883
7984??? warning "Exercise: find the bug! Expand to read the answer."
8085 If the action __ GrabBeer__ fails, the door of the
@@ -87,7 +92,7 @@ The goal of a [DecoratorNode](DecoratorNode.md) is either to transform the resul
8792from the child, to terminate the child,
8893or repeat ticking of the child, depending on the type of Decorator.
8994
90- You can create your own Decorators too .
95+ You can create your own Decorators.
9196
9297![ Simple Decorator: Enter Room] ( images/DecoratorEnterRoom.png )
9398
@@ -116,18 +121,17 @@ __But__ there is an error. Can you find it?
116121
117122### Fallback
118123
119- [ FallbackNodes] ( FallbackNode.md ) , known also as __ "Selector"__ in the literature ,
120- Is a node that is used to express, as the name suggests, fallback strategies,
121- ie. what to do if a child return FAILURE.
124+ [ FallbackNodes] ( FallbackNode.md ) , known also as __ "Selector"__ ,
125+ are nodes that can express, as the name suggests, fallback strategies,
126+ ie. what to do next if a child returns FAILURE.
122127
123- In short, it ticks the children in order, as usual from left to right and:
128+ In short, it ticks the children in order and:
124129
125130- If a child returns FAILURE, tick the next one.
126131- If a child returns SUCCESS, then no more children are ticked and the Fallback returns SUCCESS.
127132- If all the children return FAILURE, then the Fallback returns FAILURE too.
128133
129134In the next example, you can see how Sequence and Fallbacks can be combined:
130-
131135
132136![ FallbackNodes] ( images/FallbackBasic.png )
133137
@@ -162,11 +166,11 @@ returns FAILURE.
162166Both the trees will close the door of the fridge, eventually, but:
163167
164168- the tree on the __ left__ side will always return SUCCESS if we managed to
165- open and clode the fridge.
169+ open and close the fridge.
166170- the tree on the __ right__ side will return SUCCESS if the beer was there,
167171FAILURE otherwise.
168172
169- We can easily double-check that everything works as usual if __ GrabBeer__ returns SUCCESS.
173+ Everything works as expected if __ GrabBeer__ returns SUCCESS.
170174
171175![ FetchBeer success] ( images/FetchBeer2.png )
172176
0 commit comments