@@ -15,35 +15,36 @@ isolate each subtree as they were independent functions / routines, in a program
15
15
Still, there are cases where it could be desirable to have a truly "global" blackboard, that can be
16
16
accessed from every Subtree directly, without remapping.
17
17
18
- This may make sense for:
18
+ This makes sense for:
19
19
20
20
- Singletons and global objects that can't be shared as described in [ Tutorial 8] ( tutorial-basics/tutorial_08_additional_args.md )
21
21
- Global states of the robot.
22
22
- Data that is written / read outside the Behavior Tree, i.e. in the main loop executing the tick.
23
23
24
- Additionally, since the blackboard is a generic key/value storage, where the value can have ** any** type,
25
- it is a perfect data structure to implement what is known in the literature as "World Model",
26
- i.e. data that represents the state of the world, and that the Nodes in the tree may need to access .
24
+ Additionally, since the blackboard is a generic key/value storage, where the value can contain ** any** type,
25
+ it is a perfect data structure to implement what is known in the literature as ** "World Model"** ,
26
+ i.e. a place where the states of the environment, the robot and the tasks can be shared with the Behavior Trees .
27
27
28
+ ## Blackboards hierarchy
28
29
29
30
Consider a simple Tree with two subtrees, like this:
30
31
31
32
![ tree_hierarchy.png] ( images/tree_hierarchy.png )
32
33
33
- Each one of the 3 Subtree has its own blackboard; the parent. child relationship between these
34
- blackboards is exactly the same as the BehaviorTrees , i.e. BB1 is the parent of BB2 and BB3.
34
+ Each one of the 3 Subtree has its own blackboard; the parent / child relationship between these
35
+ blackboards is exactly the same as the tree , i.e. BB1 is the parent of BB2 and BB3.
35
36
36
37
The lifecycle of these individual blackboards is coupled with their respective Subtree.
37
38
38
- We will can introduce easily an external "global blackboard" like this:
39
+ We can implement an external "global blackboard" like this:
39
40
40
41
``` cpp
41
42
auto global_bb = BT::Blackboard::create();
42
43
auto maintree_bb = BT::Blackboard::create(global_bb);
43
44
auto tree = factory.createTree(" MainTree" , maintree_bb);
44
45
```
45
46
46
- This will create the following hierarchy, among blackboards:
47
+ This will create the following blackboards hierarchy :
47
48
48
49
![ bb_hierarchy.png] ( images/bb_hierarchy.png )
49
50
@@ -54,22 +55,21 @@ Furthermore, it can be easily accessed using `set` and `get` methods.
54
55
55
56
## How to access the top-level blackboard from the tree
56
57
57
- We call a blackboard the "top-level" one, when it is the root or the hierarchy.
58
+ By "top-level blackboard", we mean the one at the root or the hierarchy.
58
59
59
- In the previous tutorials, that would be the one inside "MainTree", but when the code above
60
- is used, ` global_bb ` will become the top-level one.
60
+ In the code above, ` global_bb ` becomes the top-level blackboard.
61
61
62
62
Since version ** 4.6** of BT.CPP, a new syntax was introduced to access the top-level
63
- blackboard ** without remapping** .
63
+ blackboard ** without remapping** , by adding the prefix ` @ ` to the name of the entry.
64
64
65
- Simply, add the prefix "@" to the name of the entry. For instance:
65
+ For instance:
66
66
67
67
68
68
``` xml
69
69
<PrintNumber val =" {@value}" />
70
70
```
71
71
72
- This code will always search the entry ` value ` in the top-level blackboard, instead of the local one.
72
+ The port ** val ** will search the entry ` value ` in the top-level blackboard, instead of the local one.
73
73
74
74
## Full example
75
75
@@ -100,18 +100,18 @@ public:
100
100
PrintNumber (const std::string& name, const BT::NodeConfig& config)
101
101
: BT::SyncActionNode(name, config)
102
102
{}
103
+
104
+ static BT::PortsList providedPorts()
105
+ {
106
+ return { BT::InputPort<int >("val") };
107
+ }
103
108
104
109
NodeStatus tick() override
105
110
{
106
111
const int val = getInput<int >("val").value();
107
112
std::cout << "[ " << name() << "] val: " << val << std::endl;
108
113
return NodeStatus::SUCCESS;
109
114
}
110
-
111
- static BT::PortsList providedPorts()
112
- {
113
- return { BT::InputPort<int >("val") };
114
- }
115
115
};
116
116
117
117
int main()
@@ -160,6 +160,6 @@ Output:
160
160
161
161
Notes:
162
162
163
- - The prefix "@" works both when used in an InputPort or in the scripting language.
163
+ - The prefix "@" works both when used in an Input / Output Port or in the scripting language.
164
164
- No remapping is needed in the Subtrees.
165
165
- When accessing the blackboard directly in the main loop, no prefix "@" is needed.
0 commit comments