t06_subtree_port_remapping.cpp
Go to the documentation of this file.
3 
4 #include "movebase_node.h"
5 #include "dummy_nodes.h"
6 
21 // clang-format off
22 
23 static const char* xml_text = R"(
24 <root main_tree_to_execute = "MainTree">
25 
26  <BehaviorTree ID="MainTree">
27 
28  <Sequence name="main_sequence">
29  <SetBlackboard output_key="move_goal" value="1;2;3" />
30  <SubTree ID="MoveRobot" target="move_goal" output="move_result" />
31  <SaySomething message="{move_result}"/>
32  </Sequence>
33 
34  </BehaviorTree>
35 
36  <BehaviorTree ID="MoveRobot">
37  <Fallback name="move_robot_main">
38  <SequenceStar>
39  <MoveBase goal="{target}"/>
40  <SetBlackboard output_key="output" value="mission accomplished" />
41  </SequenceStar>
42  <ForceFailure>
43  <SetBlackboard output_key="output" value="mission failed" />
44  </ForceFailure>
45  </Fallback>
46  </BehaviorTree>
47 
48 </root>
49  )";
50 
51 // clang-format on
52 
53 using namespace BT;
54 using namespace DummyNodes;
55 
56 int main()
57 {
58  BehaviorTreeFactory factory;
59 
60  factory.registerNodeType<SaySomething>("SaySomething");
61  factory.registerNodeType<MoveBaseAction>("MoveBase");
62 
63  auto tree = factory.createTreeFromText(xml_text);
64 
65  tree.tickRootWhileRunning();
66 
67  // let's visualize some information about the current state of the blackboards.
68  std::cout << "--------------" << std::endl;
69  tree.blackboard_stack[0]->debugMessage();
70  std::cout << "--------------" << std::endl;
71  tree.blackboard_stack[1]->debugMessage();
72  std::cout << "--------------" << std::endl;
73 
74  return 0;
75 }
76 
77 /* Expected output:
78 
79  [ MoveBase: STARTED ]. goal: x=1 y=2.0 theta=3.00
80  [ MoveBase: FINISHED ]
81  Robot says: mission accomplished
82  --------------
83  move_result (std::string) -> full
84  move_goal (Pose2D) -> full
85  --------------
86  output (std::string) -> remapped to parent [move_result]
87  target (Pose2D) -> remapped to parent [move_goal]
88  --------------
89 
90 */
BT
Definition: ex01_wrap_legacy.cpp:29
BT::BehaviorTreeFactory::registerNodeType
void registerNodeType(const std::string &ID)
Definition: bt_factory.h:364
bt_factory.h
DummyNodes
Definition: dummy_nodes.cpp:10
MoveBaseAction
Definition: movebase_node.h:43
dummy_nodes.h
xml_text
static const char * xml_text
Definition: t06_subtree_port_remapping.cpp:23
movebase_node.h
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:278
bt_cout_logger.h
DummyNodes::SaySomething
Definition: dummy_nodes.h:50
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:251
main
int main()
Definition: t06_subtree_port_remapping.cpp:56


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