File tree Expand file tree Collapse file tree 2 files changed +48
-13
lines changed Expand file tree Collapse file tree 2 files changed +48
-13
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ namespace BT
1616{
1717NodeStatus ReactiveSequence::tick ()
1818{
19- size_t success_count = 0 ;
2019 bool all_skipped = true ;
2120 setStatus (NodeStatus::RUNNING);
2221
@@ -44,14 +43,9 @@ NodeStatus ReactiveSequence::tick()
4443 resetChildren ();
4544 return NodeStatus::FAILURE;
4645 }
47- case NodeStatus::SUCCESS: {
48- success_count++;
49- }
50- break ;
51-
52- case NodeStatus::SKIPPED: {
53- // node skipped
54- }
46+ // do nothing if SUCCESS or SKIPPED
47+ case NodeStatus::SUCCESS:
48+ case NodeStatus::SKIPPED:
5549 break ;
5650
5751 case NodeStatus::IDLE: {
@@ -60,10 +54,8 @@ NodeStatus ReactiveSequence::tick()
6054 } // end switch
6155 } // end for
6256
63- if (success_count == childrenCount ())
64- {
65- resetChildren ();
66- }
57+ resetChildren ();
58+
6759 // Skip if ALL the nodes have been skipped
6860 return all_skipped ? NodeStatus::SKIPPED : NodeStatus::SUCCESS;
6961}
Original file line number Diff line number Diff line change @@ -114,3 +114,46 @@ TEST(SkippingLogic, ReactiveSingleChild)
114114
115115 tree.tickWhileRunning ();
116116}
117+
118+ TEST (SkippingLogic, SkippingReactiveSequence)
119+ {
120+ BehaviorTreeFactory factory;
121+ std::array<int , 2 > counters;
122+ RegisterTestTick (factory, " Test" , counters);
123+
124+ const std::string xml_text = R"(
125+ <root BTCPP_format="4" >
126+ <BehaviorTree>
127+ <Sequence>
128+ <ReactiveSequence>
129+ <Script code=" value:=50 "/>
130+ <TestA _skipIf="value < 25"/>
131+ </ReactiveSequence>
132+
133+ <ReactiveSequence>
134+ <Script code=" value:=10 "/>
135+ <TestB _skipIf="value < 25"/>
136+ </ReactiveSequence>
137+ </Sequence>
138+ </BehaviorTree>
139+ </root>)" ;
140+
141+ auto tree = factory.createTreeFromText (xml_text);
142+
143+ BT::NodeStatus status;
144+ try {
145+ int runs = 0 ;
146+ while (runs < 5 )
147+ {
148+ status = tree.tickOnce ();
149+ tree.sleep (std::chrono::milliseconds (10 ));
150+ runs++;
151+ }
152+ } catch (BT::LogicError err) {
153+ std::cout << err.what () << std::endl;
154+ }
155+
156+ ASSERT_EQ (status, NodeStatus::SUCCESS);
157+ ASSERT_EQ (counters[0 ], 5 );
158+ ASSERT_EQ (counters[1 ], 0 );
159+ }
You can’t perform that action at this time.
0 commit comments