@@ -63,11 +63,11 @@ NodeStatus MoveBaseAction::tick()
6363 int count = 0;
6464
6565 // Pretend that "computing" takes 250 milliseconds.
66- // It is up to you to check periodicall _halt_requested and interrupt
66+ // It is up to you to check periodically _halt_requested and interrupt
6767 // this tick() if it is true.
6868 while (!_halt_requested && count++ < 25)
6969 {
70- SleepMS (10 );
70+ std::this_thread::sleep_for ( std::chrono::milliseconds (10) );
7171 }
7272
7373 std::cout << "[ MoveBase: FINISHED ]" << std::endl;
@@ -105,6 +105,7 @@ The following example should use a simple `SequenceNode`.
105105int main ()
106106{
107107 using namespace DummyNodes;
108+ using std::chrono::milliseconds;
108109
109110 BehaviorTreeFactory factory;
110111 factory.registerSimpleCondition("BatteryOK", std::bind(CheckBattery));
@@ -118,11 +119,11 @@ int main()
118119 std::cout << "\n--- 1st executeTick() ---" << std::endl;
119120 status = tree.tickRoot();
120121
121- SleepMS ( 150);
122+ tree.sleep( milliseconds( 150) );
122123 std::cout << "\n--- 2nd executeTick() ---" << std::endl;
123124 status = tree.tickRoot();
124125
125- SleepMS ( 150);
126+ tree.sleep( milliseconds( 150) );
126127 std::cout << "\n--- 3rd executeTick() ---" << std::endl;
127128 status = tree.tickRoot();
128129
@@ -191,5 +192,15 @@ Expected output:
191192 Robot says: "mission completed!"
192193```
193194
195+ ## Event Driven trees?
196+
197+ !!! important
198+ We used the command ` tree.sleep() ` instead of ` std::this_thread::sleep_for() ` for a reason.
199+
200+ The method ` Tree::sleep() ` should be preferred, because it can be interrupted by a Node in the tree when
201+ "something changed".
202+ Tree::sleep() will be interrupted when an ` AsyncActionNode::tick() ` is completed or, more generally,
203+ when the method ` TreeNode::emitStateChanged() ` is invoked.
204+
194205
195206
0 commit comments