t05_crossdoor.cpp
Go to the documentation of this file.
1 #include "crossdoor_nodes.h"
2 
7 
8 #ifdef ZMQ_FOUND
10 #endif
11 
21 // clang-format off
22 
23 static const char* xml_text = R"(
24 <root main_tree_to_execute = "MainTree">
25  <!--------------------------------------->
26  <BehaviorTree ID="DoorClosed">
27  <Sequence name="door_closed_sequence">
28  <Inverter>
29  <Condition ID="IsDoorOpen"/>
30  </Inverter>
31  <RetryUntilSuccessful num_attempts="4">
32  <OpenDoor/>
33  </RetryUntilSuccessful>
34  <PassThroughDoor/>
35  </Sequence>
36  </BehaviorTree>
37  <!--------------------------------------->
38  <BehaviorTree ID="MainTree">
39  <Sequence>
40  <Fallback name="root_Fallback">
41  <Sequence name="door_open_sequence">
42  <IsDoorOpen/>
43  <PassThroughDoor/>
44  </Sequence>
45  <SubTree ID="DoorClosed"/>
46  <PassThroughWindow/>
47  </Fallback>
48  <CloseDoor/>
49  </Sequence>
50  </BehaviorTree>
51  <!--------------------------------------->
52 </root>
53  )";
54 
55 // clang-format on
56 
57 using namespace BT;
58 
59 int main(int argc, char** argv)
60 {
62 
63  // Register our custom nodes into the factory.
64  // Any default nodes provided by the BT library (such as Fallback) are registered by
65  // default in the BehaviorTreeFactory.
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  // This logger prints state changes on console
72  StdCoutLogger logger_cout(tree);
73 
74  // This logger saves state changes on file
75  FileLogger logger_file(tree, "bt_trace.fbl");
76 
77  // This logger stores the execution time of each node
78  MinitraceLogger logger_minitrace(tree, "bt_trace.json");
79 
80 #ifdef ZMQ_FOUND
81  // This logger publish status changes using ZeroMQ. Used by Groot
82  PublisherZMQ publisher_zmq(tree);
83 #endif
84 
85  printTreeRecursively(tree.rootNode());
86 
87  const bool LOOP = (argc == 2 && strcmp(argv[1], "loop") == 0);
88 
89  NodeStatus status = tree.tickRoot();
90  while(LOOP || status == NodeStatus::RUNNING)
91  {
92  tree.sleep(std::chrono::milliseconds(10));
93  status = tree.tickRoot();
94  }
95 
96  return 0;
97 }
BT
Definition: ex01_wrap_legacy.cpp:29
bt_zmq_publisher.h
xml_text
static const char * xml_text
Definition: t05_crossdoor.cpp:23
BT::PublisherZMQ
Definition: bt_zmq_publisher.h:10
BT::FileLogger
Definition: bt_file_logger.h:11
bt_file_logger.h
bt_factory.h
CrossDoor::RegisterNodes
void RegisterNodes(BT::BehaviorTreeFactory &factory)
Definition: crossdoor_nodes.cpp:76
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:278
bt_cout_logger.h
BT::MinitraceLogger
Definition: bt_minitrace_logger.h:9
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:251
crossdoor_nodes.h
BT::NodeStatus::RUNNING
@ RUNNING
BT::printTreeRecursively
void printTreeRecursively(const TreeNode *root_node, std::ostream &stream=std::cout)
Definition: behavior_tree.cpp:68
main
int main(int argc, char **argv)
Definition: t05_crossdoor.cpp:59
BT::NodeStatus
NodeStatus
Definition: basic_types.h:35
bt_minitrace_logger.h
BT::StdCoutLogger
AddStdCoutLoggerToTree. Give the root node of a tree, a simple callback is subscribed to any status c...
Definition: bt_cout_logger.h:19


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19