plugin_executor.cpp
Go to the documentation of this file.
3 
4 static const char* xml_text = R"(
5 
6 // clang-format off
7  <root BTCPP_format="4" main_tree_to_execute="MainTree" >
8  <BehaviorTree ID="MainTree">
9  <Sequence>
10  <Script code="vect:='1,2,3,4'"/>
11  <PrintVector value="{vect}"/>;
12  <SubTree ID="MySub" v4="{vect}"/>
13  </Sequence>
14  </BehaviorTree>
15 
16  <BehaviorTree ID="MySub">
17  <PrintVector value="{v4}"/>;
18  </BehaviorTree>
19  </root>
20  )";
21 // clang-format on
22 
23 int main(int argc, char** argv)
24 {
25  using namespace BT;
26  BehaviorTreeFactory factory;
27 
28  std::string plugin_path = "test_plugin_action.so";
29 
30  // if you don't want to use the hardcoded path, pass it as an argument
31  if(argc == 2)
32  {
33  plugin_path = argv[1];
34  }
35 
36  // load the plugin. This will register the action "PrintVector"
37  factory.registerFromPlugin(plugin_path);
38 
39  // print the registered model of PrintVector
40  std::cout << writeTreeNodesModelXML(factory, false) << std::endl;
41 
42  auto tree = factory.createTreeFromText(xml_text);
43  tree.tickWhileRunning();
44 
45  return 0;
46 }
BT
Definition: ex01_wrap_legacy.cpp:29
BT::BehaviorTreeFactory::registerFromPlugin
void registerFromPlugin(const std::string &file_path)
registerFromPlugin load a shared library and execute the function BT_REGISTER_NODES (see macro).
Definition: bt_factory.cpp:192
bt_factory.h
xml_text
static const char * xml_text
Definition: plugin_executor.cpp:4
BT::Tree::tickWhileRunning
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
Definition: bt_factory.cpp:610
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
createTreeFromText will parse the XML directly from string. The XML needs to contain either a single ...
Definition: bt_factory.cpp:395
xml_parsing.h
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:209
main
int main(int argc, char **argv)
Definition: plugin_executor.cpp:23
BT::writeTreeNodesModelXML
std::string writeTreeNodesModelXML(const BehaviorTreeFactory &factory, bool include_builtin=false)
writeTreeNodesModelXML generates an XMl that contains the manifests in the <TreeNodesModel>
Definition: xml_parsing.cpp:1214


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