MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / main

Function main

examples/ex01_wrap_legacy.cpp:69–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67// clang-format on
68
69int main()
70{
71 using namespace BT;
72
73 MyLegacyMoveTo move_to;
74
75 // Here we use a lambda that captures the reference of move_to
76 auto MoveToWrapperWithLambda = [&move_to](TreeNode& parent_node) -> NodeStatus {
77 Point3D goal{};
78 // thanks to paren_node, you can access easily the input and output ports.
79 parent_node.getInput("goal", goal);
80
81 bool res = move_to.go(goal);
82 // convert bool to NodeStatus
83 return res ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
84 };
85
86 BehaviorTreeFactory factory;
87
88 // Register the lambda with BehaviorTreeFactory::registerSimpleAction
89
90 PortsList ports = { BT::InputPort<Point3D>("goal") };
91 factory.registerSimpleAction("MoveTo", MoveToWrapperWithLambda, ports);
92
93 auto tree = factory.createTreeFromText(xml_text);
94
95 tree.tickWhileRunning();
96
97 return 0;
98}
99
100/* Expected output:
101

Callers

nothing calls this directly

Calls 5

goMethod · 0.80
registerSimpleActionMethod · 0.80
createTreeFromTextMethod · 0.80
tickWhileRunningMethod · 0.80
getInputMethod · 0.45

Tested by

no test coverage detected