examples
t06_subtree_port_remapping.cpp
Go to the documentation of this file.
1
#include "
behaviortree_cpp/loggers/bt_cout_logger.h
"
2
#include "
behaviortree_cpp/bt_factory.h
"
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 BTCPP_format="4">
25
26
<BehaviorTree ID="MainTree">
27
<Sequence>
28
<Script code=" move_goal='1;2;3' " />
29
<SubTree ID="MoveRobot" target="{move_goal}" result="{move_result}" />
30
<SaySomething message="{move_result}"/>
31
</Sequence>
32
</BehaviorTree>
33
34
<BehaviorTree ID="MoveRobot">
35
<Fallback>
36
<Sequence>
37
<MoveBase goal="{target}"/>
38
<Script code=" result:='goal reached' " />
39
</Sequence>
40
<ForceFailure>
41
<Script code=" result:='error' " />
42
</ForceFailure>
43
</Fallback>
44
</BehaviorTree>
45
46
</root>
47
)";
48
49
// clang-format on
50
51
using namespace
BT
;
52
using namespace
DummyNodes
;
53
54
int
main
()
55
{
56
BehaviorTreeFactory
factory;
57
58
factory.
registerNodeType
<
SaySomething
>(
"SaySomething"
);
59
factory.
registerNodeType
<
MoveBaseAction
>(
"MoveBase"
);
60
61
factory.
registerBehaviorTreeFromText
(
xml_text
);
62
auto
tree = factory.
createTree
(
"MainTree"
);
63
64
tree.
tickWhileRunning
();
65
66
// let's visualize some information about the current state of the blackboards.
67
std::cout <<
"\n------ First BB ------"
<< std::endl;
68
tree.subtrees[0]->blackboard->debugMessage();
69
std::cout <<
"\n------ Second BB------"
<< std::endl;
70
tree.subtrees[1]->blackboard->debugMessage();
71
72
return
0;
73
}
74
75
/* Expected output:
76
77
------ First BB ------
78
move_result (std::string)
79
move_goal (Pose2D)
80
81
------ Second BB------
82
[result] remapped to port of parent tree [move_result]
83
[target] remapped to port of parent tree [move_goal]
84
85
*/
BT
Definition:
ex01_wrap_legacy.cpp:29
BT::BehaviorTreeFactory::createTree
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
Definition:
bt_factory.cpp:432
bt_factory.h
DummyNodes
Definition:
dummy_nodes.cpp:10
MoveBaseAction
Definition:
movebase_node.h:54
BT::Tree::tickWhileRunning
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
Definition:
bt_factory.cpp:610
dummy_nodes.h
xml_text
static const char * xml_text
Definition:
t06_subtree_port_remapping.cpp:23
movebase_node.h
BT::BehaviorTreeFactory::registerNodeType
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
Definition:
bt_factory.h:326
bt_cout_logger.h
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:
t06_subtree_port_remapping.cpp:54
behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17