t14_subtree_model.cpp
Go to the documentation of this file.
3 
4 using namespace BT;
5 
6 /*
7  * Demonstrate how to use a SubTree Model (since version 4.4)
8  */
9 
24 // clang-format off
25 static const char* xml_subtree = R"(
26 <root BTCPP_format="4">
27 
28  <TreeNodesModel>
29  <SubTree ID="MySub">
30  <input_port name="sub_in_value" default="42"/>
31  <input_port name="sub_in_name"/>
32  <output_port name="sub_out_result" default="{out_result}"/>
33  <output_port name="sub_out_state"/>
34  </SubTree>
35  </TreeNodesModel>
36 
37  <BehaviorTree ID="MySub">
38  <Sequence>
39  <ScriptCondition code="sub_in_value==42 && sub_in_name=='john'" />
40  <Script code="sub_out_result:=69; sub_out_state:='ACTIVE'" />
41  </Sequence>
42  </BehaviorTree>
43 </root>
44  )";
45 
51 static const char* xml_maintree = R"(
52 <root BTCPP_format="4">
53 
54  <BehaviorTree ID="MainTree">
55  <Sequence>
56  <Script code="in_name:= 'john' "/>
57  <SubTree ID="MySub" sub_in_name="{in_name}"
58  sub_out_state="{out_state}"/>
59  <ScriptCondition code=" out_result==69 && out_state=='ACTIVE' " />
60  </Sequence>
61  </BehaviorTree>
62 
63 </root>
64  )";
65 
66 // clang-format on
67 
68 int main()
69 {
70  BehaviorTreeFactory factory;
73 
74  auto tree = factory.createTree("MainTree");
75  StdCoutLogger logger(tree);
76  tree.tickWhileRunning();
77 
78  // We expect the sequence to be successful.
79 
80  // The full remapping was:
81  //
82  // - sub_in_name <-> {in_name} // specified by callee 'MainTree'
83  // - sub_in_value <-> 42 // default remapping, see model
84  // - sub_out_result <-> {out_result} // default remapping, see model
85  // - sub_out_state <-> {out_state} // specified by callee 'MainTree'
86 
87  return 0;
88 }
BT
Definition: ex01_wrap_legacy.cpp:29
main
int main()
Definition: t14_subtree_model.cpp:68
BT::BehaviorTreeFactory::createTree
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:432
xml_maintree
static const char * xml_maintree
Definition: t14_subtree_model.cpp:51
bt_factory.h
bt_cout_logger.h
convert_v3_to_v4.logger
logger
Definition: convert_v3_to_v4.py:12
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:205
xml_subtree
static const char * xml_subtree
Definition: t14_subtree_model.cpp:25
BT::BehaviorTreeFactory::registerBehaviorTreeFromText
void registerBehaviorTreeFromText(const std::string &xml_text)
Definition: bt_factory.cpp:277
BT::StdCoutLogger
StdCoutLogger is a very simple logger that displays all the transitions on the console.
Definition: bt_cout_logger.h:14


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:08