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

Function main

examples/t04_reactive_sequence.cpp:60–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58using namespace DummyNodes;
59
60int 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}

Callers

nothing calls this directly

Calls 7

bindFunction · 0.85
createTreeFromTextMethod · 0.80
tickWhileRunningMethod · 0.80
tickOnceMethod · 0.80
sleepMethod · 0.80
toStrFunction · 0.50

Tested by

no test coverage detected