forked from BehaviorTree/btcpp_sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (50 loc) · 1.56 KB
/
main.cpp
File metadata and controls
68 lines (50 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "behaviortree_cpp/bt_factory.h"
using namespace BT;
// clang-format off
static const char* xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<ReceiveNodeEnums input_node_status="IDLE" input_node_type="Control" />
</BehaviorTree>
</root>
)";
// clang-format on
class ReceiveNodeEnums : public BT::SyncActionNode
{
public:
ReceiveNodeEnums(const std::string& name, const BT::NodeConfig& config) :
BT::SyncActionNode(name, config)
{
// NodeType another_node_type;
// getInput("input_node_type", another_node_type); Uncomment to trigger Seg fault.
}
BT::NodeStatus tick() override
{
NodeStatus node_status;
NodeType node_type;
getInput("input_node_status", node_status);
getInput("input_node_type", node_type);
std::cout << "Inside tick() with getInput:" << std::endl;
std::cout << node_status << std::endl;
std::cout << node_type << std::endl << std::endl;
return BT::NodeStatus::SUCCESS;
}
static BT::PortsList providedPorts()
{
return {
BT::InputPort<NodeStatus>("input_node_status"),
BT::InputPort<NodeType>("input_node_type"),
};
}
};
int main()
{
BehaviorTreeFactory factory;
factory.registerNodeType<ReceiveNodeEnums>("ReceiveNodeEnums");
auto tree = factory.createTreeFromText(xml_text);
tree.tickWhileRunning();
std::cout << "Without getInput: " << std::endl;
std::cout << convertFromString<NodeStatus>("IDLE") << std::endl;
std::cout << convertFromString<NodeType>("Control") << std::endl << std::endl;
return 0;
}