@@ -15,35 +15,36 @@ isolate each subtree as they were independent functions / routines, in a program
1515Still, there are cases where it could be desirable to have a truly "global" blackboard, that can be
1616accessed from every Subtree directly, without remapping.
1717
18- This may make sense for:
18+ This makes sense for:
1919
2020- Singletons and global objects that can't be shared as described in [ Tutorial 8] ( tutorial-basics/tutorial_08_additional_args.md )
2121- Global states of the robot.
2222- Data that is written / read outside the Behavior Tree, i.e. in the main loop executing the tick.
2323
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 .
2727
28+ ## Blackboards hierarchy
2829
2930Consider a simple Tree with two subtrees, like this:
3031
3132![ tree_hierarchy.png] ( images/tree_hierarchy.png )
3233
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.
3536
3637The lifecycle of these individual blackboards is coupled with their respective Subtree.
3738
38- We will can introduce easily an external "global blackboard" like this:
39+ We can implement an external "global blackboard" like this:
3940
4041``` cpp
4142auto global_bb = BT::Blackboard::create();
4243auto maintree_bb = BT::Blackboard::create(global_bb);
4344auto tree = factory.createTree(" MainTree" , maintree_bb);
4445```
4546
46- This will create the following hierarchy, among blackboards:
47+ This will create the following blackboards hierarchy :
4748
4849![ bb_hierarchy.png] ( images/bb_hierarchy.png )
4950
@@ -54,22 +55,21 @@ Furthermore, it can be easily accessed using `set` and `get` methods.
5455
5556## How to access the top-level blackboard from the tree
5657
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.
5859
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.
6161
6262Since 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.
6464
65- Simply, add the prefix "@" to the name of the entry. For instance:
65+ For instance:
6666
6767
6868``` xml
6969<PrintNumber val =" {@value}" />
7070```
7171
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.
7373
7474## Full example
7575
@@ -100,18 +100,18 @@ public:
100100 PrintNumber (const std::string& name, const BT::NodeConfig& config)
101101 : BT::SyncActionNode(name, config)
102102 {}
103+
104+ static BT::PortsList providedPorts()
105+ {
106+ return { BT::InputPort<int >("val") };
107+ }
103108
104109 NodeStatus tick() override
105110 {
106111 const int val = getInput<int >("val").value();
107112 std::cout << "[ " << name() << "] val: " << val << std::endl;
108113 return NodeStatus::SUCCESS;
109114 }
110-
111- static BT::PortsList providedPorts()
112- {
113- return { BT::InputPort<int >("val") };
114- }
115115};
116116
117117int main()
@@ -160,6 +160,6 @@ Output:
160160
161161Notes:
162162
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.
164164- No remapping is needed in the Subtrees.
165165- When accessing the blackboard directly in the main loop, no prefix "@" is needed.
0 commit comments