t07_load_multiple_xml.cpp
Go to the documentation of this file.
1 #include "dummy_nodes.h"
3 
9 // clang-format off
10 
11 static const char* xml_text_main = R"(
12 <root BTCPP_format="4">
13  <BehaviorTree ID="MainTree">
14  <Sequence>
15  <SaySomething message="starting MainTree" />
16  <SubTree ID="SubA"/>
17  <SubTree ID="SubB"/>
18  </Sequence>
19  </BehaviorTree>
20 </root> )";
21 
22 static const char* xml_text_subA = R"(
23 <root BTCPP_format="4">
24  <BehaviorTree ID="SubA">
25  <SaySomething message="Executing SubA" />
26  </BehaviorTree>
27 </root> )";
28 
29 static const char* xml_text_subB = R"(
30 <root BTCPP_format="4">
31  <BehaviorTree ID="SubB">
32  <SaySomething message="Executing SubB" />
33  </BehaviorTree>
34 </root> )";
35 
36 // clang-format on
37 
38 using namespace BT;
39 
40 int main()
41 {
43  factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
44 
45  // Register the behavior tree definitions, but do not instantiate them yet.
46  // Order is not important.
50 
51  //Check that the BTs have been registered correctly
52  std::cout << "Registered BehaviorTrees:" << std::endl;
53  for(const std::string& bt_name : factory.registeredBehaviorTrees())
54  {
55  std::cout << " - " << bt_name << std::endl;
56  }
57 
58  // You can create the MainTree and the subtrees will be added automatically.
59  std::cout << "----- MainTree tick ----" << std::endl;
60  auto main_tree = factory.createTree("MainTree");
61  main_tree.tickWhileRunning();
62 
63  // ... or you can create only one of the subtree
64  std::cout << "----- SubA tick ----" << std::endl;
65  auto subA_tree = factory.createTree("SubA");
66  subA_tree.tickWhileRunning();
67 
68  return 0;
69 }
70 /* Expected output:
71 
72 Registered BehaviorTrees:
73  - MainTree
74  - SubA
75  - SubB
76 ----- MainTree tick ----
77 Robot says: starting MainTree
78 Robot says: Executing SubA
79 Robot says: Executing SubB
80 ----- SubA tick ----
81 Robot says: Executing SubA
82 
83 */
BT
Definition: ex01_wrap_legacy.cpp:29
xml_text_main
static const char * xml_text_main
Definition: t07_load_multiple_xml.cpp:11
BT::BehaviorTreeFactory::registeredBehaviorTrees
std::vector< std::string > registeredBehaviorTrees() const
Definition: bt_factory.cpp:282
BT::BehaviorTreeFactory::createTree
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:432
xml_text_subA
static const char * xml_text_subA
Definition: t07_load_multiple_xml.cpp:22
xml_text_subB
static const char * xml_text_subB
Definition: t07_load_multiple_xml.cpp:29
bt_factory.h
BT::Tree::tickWhileRunning
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
Definition: bt_factory.cpp:610
dummy_nodes.h
BT::BehaviorTreeFactory::registerNodeType
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
Definition: bt_factory.h:326
DummyNodes::SaySomething
Definition: dummy_nodes.h:47
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:209
BT::BehaviorTreeFactory::registerBehaviorTreeFromText
void registerBehaviorTreeFromText(const std::string &xml_text)
Definition: bt_factory.cpp:277
main
int main()
Definition: t07_load_multiple_xml.cpp:40


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