| 46 | */ |
| 47 | |
| 48 | int main(int /*argc*/, char** /*argv*/) |
| 49 | { |
| 50 | using namespace DummyNodes; |
| 51 | BT::BehaviorTreeFactory factory; |
| 52 | factory.registerNodeType<SaySomething>("SaySomething"); |
| 53 | factory.registerBehaviorTreeFromText(xml_text); |
| 54 | |
| 55 | // let's check what the "original" tree should return |
| 56 | { |
| 57 | auto tree = factory.createTree("MainTree"); |
| 58 | |
| 59 | std::cout << "----- Nodes fullPath() -------\n"; |
| 60 | // as a reminder, let's print the full names of all the nodes |
| 61 | tree.applyVisitor( |
| 62 | [](BT::TreeNode* node) { std::cout << node->fullPath() << std::endl; }); |
| 63 | |
| 64 | std::cout << "\n------ Output (original) ------\n"; |
| 65 | tree.tickWhileRunning(); |
| 66 | } |
| 67 | |
| 68 | // We have three mechanisms to create Nodes to be used as "mocks". |
| 69 | // We will see later how to use them. |
| 70 | |
| 71 | //--------------------------------------------------------------- |
| 72 | // Mock type 1: register a specific "dummy" Node into the factory |
| 73 | // You can use any registration method, but to keep this short, |
| 74 | // we use registerSimpleAction() |
| 75 | |
| 76 | factory.registerSimpleAction("DummyAction", [](BT::TreeNode& self) { |
| 77 | std::cout << "DummyAction substituting node with fullPath(): " << self.fullPath() |
| 78 | << std::endl; |
| 79 | return BT::NodeStatus::SUCCESS; |
| 80 | }); |
| 81 | |
| 82 | factory.registerSimpleAction("DummySaySomething", [](BT::TreeNode& self) { |
| 83 | auto msg = self.getInput<std::string>("message"); |
| 84 | std::cout << "DummySaySomething: " << msg.value() << std::endl; |
| 85 | return BT::NodeStatus::SUCCESS; |
| 86 | }); |
| 87 | |
| 88 | //--------------------------------------------------------------- |
| 89 | // Mock type 2: Use our configurable BT::TestNode |
| 90 | |
| 91 | // This is the configuration passed to the TestNode |
| 92 | BT::TestNodeConfig test_config; |
| 93 | // we want this to return always SUCCESS |
| 94 | test_config.return_status = BT::NodeStatus::SUCCESS; |
| 95 | // Convert the node in asynchronous and wait 2000 ms |
| 96 | test_config.async_delay = std::chrono::milliseconds(2000); |
| 97 | // Execute this postcondition, once completed |
| 98 | test_config.post_script = "msg := 'message SUBSTITUTED' "; |
| 99 | |
| 100 | // this will be synchronous (async_delay is 0) |
| 101 | BT::TestNodeConfig counting_config; |
| 102 | counting_config.return_status = BT::NodeStatus::SUCCESS; |
| 103 | |
| 104 | //--------------------------------------------------------------- |
| 105 | // Next, we want to substitute one or more of out Nodes with this mocks |
nothing calls this directly
no test coverage detected