| 58 | using namespace DummyNodes; |
| 59 | |
| 60 | int main() |
| 61 | { |
| 62 | BehaviorTreeFactory factory; |
| 63 | |
| 64 | factory.registerSimpleCondition("BatteryOK", std::bind(CheckBattery)); |
| 65 | factory.registerNodeType<MoveBaseAction>("MoveBase"); |
| 66 | factory.registerNodeType<SaySomething>("SaySomething"); |
| 67 | |
| 68 | // Compare the state transitions and messages using either |
| 69 | // xml_text_sequence and xml_text_reactive. |
| 70 | |
| 71 | // The main difference that you should notice is: |
| 72 | // 1) When Sequence is used, the ConditionNode is executed only __once__ because it returns SUCCESS. |
| 73 | // 2) When ReactiveSequence is used, BatteryOK is executed at __each__ tick() |
| 74 | |
| 75 | for(auto& xml_text : { xml_text_sequence, xml_text_reactive }) |
| 76 | { |
| 77 | std::cout << "\n------------ BUILDING A NEW TREE ------------\n\n"; |
| 78 | |
| 79 | auto tree = factory.createTreeFromText(xml_text); |
| 80 | |
| 81 | NodeStatus status = NodeStatus::IDLE; |
| 82 | #if 0 |
| 83 | // Tick the root until we receive either SUCCESS or RUNNING |
| 84 | // same as: tree.tickRoot(Tree::WHILE_RUNNING) |
| 85 | std::cout << "--- ticking\n"; |
| 86 | status = tree.tickWhileRunning(); |
| 87 | std::cout << "--- status: " << toStr(status) << "\n\n"; |
| 88 | #else |
| 89 | // If we need to run code between one tick() and the next, |
| 90 | // we can implement our own while loop |
| 91 | while(status != NodeStatus::SUCCESS) |
| 92 | { |
| 93 | std::cout << "--- ticking\n"; |
| 94 | status = tree.tickOnce(); |
| 95 | std::cout << "--- status: " << toStr(status) << "\n\n"; |
| 96 | |
| 97 | // if still running, add some wait time |
| 98 | if(status == NodeStatus::RUNNING) |
| 99 | { |
| 100 | tree.sleep(std::chrono::milliseconds(100)); |
| 101 | } |
| 102 | } |
| 103 | #endif |
| 104 | } |
| 105 | return 0; |
| 106 | } |
nothing calls this directly
no test coverage detected