t05_crossdoor.cpp
Go to the documentation of this file.
1 #include "crossdoor_nodes.h"
3 
10 // clang-format off
11 
12 static const char* xml_text = R"(
13 <root BTCPP_format="4">
14 
15  <BehaviorTree ID="MainTree">
16  <Sequence>
17  <Fallback>
18  <Inverter>
19  <IsDoorClosed/>
20  </Inverter>
21  <SubTree ID="DoorClosed"/>
22  </Fallback>
23  <PassThroughDoor/>
24  </Sequence>
25  </BehaviorTree>
26 
27  <BehaviorTree ID="DoorClosed">
28  <Fallback>
29  <OpenDoor/>
30  <RetryUntilSuccessful num_attempts="5">
31  <PickLock/>
32  </RetryUntilSuccessful>
33  <SmashDoor/>
34  </Fallback>
35  </BehaviorTree>
36 
37 </root>
38  )";
39 
40 // clang-format on
41 
42 int main()
43 {
45 
46  CrossDoor cross_door;
47  cross_door.registerNodes(factory);
48 
49  // In this example a single XML contains multiple <BehaviorTree>
50  // To determine which one is the "main one", we should first register
51  // the XML and then allocate a specific tree, using its ID
52 
54  auto tree = factory.createTree("MainTree");
55 
56  // helper function to print the tree
57  BT::printTreeRecursively(tree.rootNode());
58 
59  // Tick multiple times, until either FAILURE of SUCCESS is returned
60  tree.tickWhileRunning();
61 
62  return 0;
63 }
main
int main()
Definition: t05_crossdoor.cpp:42
xml_text
static const char * xml_text
Definition: t05_crossdoor.cpp:12
BT::BehaviorTreeFactory::createTree
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:432
bt_factory.h
CrossDoor::registerNodes
void registerNodes(BT::BehaviorTreeFactory &factory)
Definition: crossdoor_nodes.cpp:56
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:209
crossdoor_nodes.h
BT::printTreeRecursively
void printTreeRecursively(const TreeNode *root_node, std::ostream &stream=std::cout)
Definition: behavior_tree.cpp:66
CrossDoor
Definition: crossdoor_nodes.h:5
BT::BehaviorTreeFactory::registerBehaviorTreeFromText
void registerBehaviorTreeFromText(const std::string &xml_text)
Definition: bt_factory.cpp:277


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17