| 67 | // clang-format on |
| 68 | |
| 69 | int 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 |
nothing calls this directly
no test coverage detected