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
16
16
{
17
17
NodeStatus ReactiveSequence::tick ()
18
18
{
19
- size_t success_count = 0 ;
20
19
bool all_skipped = true ;
21
20
setStatus (NodeStatus::RUNNING);
22
21
@@ -44,14 +43,9 @@ NodeStatus ReactiveSequence::tick()
44
43
resetChildren ();
45
44
return NodeStatus::FAILURE;
46
45
}
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:
55
49
break ;
56
50
57
51
case NodeStatus::IDLE: {
@@ -60,10 +54,8 @@ NodeStatus ReactiveSequence::tick()
60
54
} // end switch
61
55
} // end for
62
56
63
- if (success_count == childrenCount ())
64
- {
65
- resetChildren ();
66
- }
57
+ resetChildren ();
58
+
67
59
// Skip if ALL the nodes have been skipped
68
60
return all_skipped ? NodeStatus::SKIPPED : NodeStatus::SUCCESS;
69
61
}
Original file line number Diff line number Diff line change @@ -114,3 +114,46 @@ TEST(SkippingLogic, ReactiveSingleChild)
114
114
115
115
tree.tickWhileRunning ();
116
116
}
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