t05_crossdoor.cpp
Go to the documentation of this file.
1 #include "crossdoor_nodes.h"
2 
6 
8 
9 #ifdef ZMQ_FOUND
11 #endif
12 
23 // clang-format off
24 
25 static const char* xml_text = R"(
26 <root main_tree_to_execute = "MainTree">
27  <!--------------------------------------->
28  <BehaviorTree ID="DoorClosed">
29  <Sequence name="door_closed_sequence">
30  <Inverter>
31  <Condition ID="IsDoorOpen"/>
32  </Inverter>
33  <RetryUntilSuccesful num_attempts="4">
34  <OpenDoor/>
35  </RetryUntilSuccesful>
36  <PassThroughDoor/>
37  </Sequence>
38  </BehaviorTree>
39  <!--------------------------------------->
40  <BehaviorTree ID="MainTree">
41  <Sequence>
42  <Fallback name="root_Fallback">
43  <Sequence name="door_open_sequence">
44  <IsDoorOpen/>
45  <PassThroughDoor/>
46  </Sequence>
47  <SubTree ID="DoorClosed"/>
48  <PassThroughWindow/>
49  </Fallback>
50  <CloseDoor/>
51  </Sequence>
52  </BehaviorTree>
53  <!--------------------------------------->
54 </root>
55  )";
56 
57 // clang-format on
58 
59 using namespace BT;
60 
61 int main(int argc, char** argv)
62 {
64 
65  // register all the actions into the factory
66  CrossDoor::RegisterNodes(factory);
67 
68  // Important: when the object tree goes out of scope, all the TreeNodes are destroyed
69  auto tree = factory.createTreeFromText(xml_text);
70 
71  // Create some loggers
72  StdCoutLogger logger_cout(tree);
73  MinitraceLogger logger_minitrace(tree, "bt_trace.json");
74  FileLogger logger_file(tree, "bt_trace.fbl");
75 #ifdef ZMQ_FOUND
76  PublisherZMQ publisher_zmq(tree);
77 #endif
78 
79  printTreeRecursively(tree.root_node);
80 
81  const bool LOOP = ( argc == 2 && strcmp( argv[1], "loop") == 0);
82 
83  do
84  {
86  // Keep on ticking until you get either a SUCCESS or FAILURE state
87  while( status == NodeStatus::RUNNING)
88  {
89  status = tree.root_node->executeTick();
90  CrossDoor::SleepMS(1); // optional sleep to avoid "busy loops"
91  }
92  CrossDoor::SleepMS(1000);
93  }
94  while(LOOP);
95 
96  return 0;
97 }
int main(int argc, char **argv)
void SleepMS(int ms)
void printTreeRecursively(const TreeNode *root_node)
void RegisterNodes(BT::BehaviorTreeFactory &factory)
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:98
static const char * xml_text
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:170
NodeStatus
Definition: basic_types.h:35
AddStdCoutLoggerToTree. Give the root node of a tree, a simple callback is subscribed to any status c...


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:05