-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbt_executor.cpp
More file actions
37 lines (29 loc) · 1.31 KB
/
bt_executor.cpp
File metadata and controls
37 lines (29 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "behaviortree_cpp_v3/bt_factory.h"
#include "approach_object.cpp"
#include "check_battery.cpp"
#include "read_barcode.cpp"
#include "auth_nurse.cpp"
int main()
{
// We use the BehaviorTreeFactory to register our custom nodes
BT::BehaviorTreeFactory factory;
// The recommended way to create a Node is through inheritance.
factory.registerNodeType<ApproachObject>("ApproachObject");
factory.registerNodeType<ReadBarcode>("ReadBarcode");
factory.registerNodeType<AuthNurse>("AuthNurse");
// Registering a SimpleActionNode using a function pointer.
// You can use C++11 lambdas or std::bind
factory.registerSimpleCondition("CheckBattery", [&](BT::TreeNode&) { return CheckBattery(); });
// Trees are created at deployment-time (i.e. at run-time, but only
// once at the beginning).
// IMPORTANT: when the object "tree" goes out of scope, all the
// TreeNodes are destroyed
auto tree = factory.createTreeFromFile("./my_tree.xml");
// To "execute" a Tree you need to "tick" it.
// The tick is propagated to the children based on the logic of the tree.
// In this case, the entire sequence is executed, because all the children
// of the Sequence return SUCCESS.
auto result = tree.tickRootWhileRunning();
std::cout << "\nBT ended with result: " << result << std::endl;
return 0;
}