Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b58b802

Browse files
author
Davide Faconti
committed
fix ReactiveFallback too
1 parent aed23b7 commit b58b802

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

include/behaviortree_cpp/controls/reactive_fallback.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ class ReactiveFallback : public ControlNode
3939
ReactiveFallback(const std::string& name):
4040
ControlNode(name, {}){}
4141

42+
virtual void halt() override;
43+
4244
private:
4345

4446
virtual BT::NodeStatus tick() override;
47+
std::vector<bool> is_asynch_child_;
4548
};
4649

4750
}

src/controls/reactive_fallback.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,35 @@
1515
namespace BT
1616
{
1717

18+
void ReactiveFallback::halt()
19+
{
20+
std::fill(is_asynch_child_.begin(), is_asynch_child_.end(), false );
21+
ControlNode::halt();
22+
}
23+
1824
NodeStatus ReactiveFallback::tick()
1925
{
26+
is_asynch_child_.resize(childrenCount(), false);
2027
size_t failure_count = 0;
21-
size_t running_count = 0;
2228

2329
for (size_t index = 0; index < childrenCount(); index++)
2430
{
2531
TreeNode* current_child_node = children_nodes_[index];
2632
const NodeStatus child_status = current_child_node->executeTick();
2733

34+
if( is_asynch_child_[index] &&
35+
current_child_node->status() == NodeStatus::FAILURE )
36+
{
37+
failure_count++;
38+
continue; // skip already executed asynch children
39+
}
40+
2841
switch (child_status)
2942
{
3043
case NodeStatus::RUNNING:
3144
{
32-
haltChildren(0);
45+
is_asynch_child_[index] = true;
46+
haltChildren(index+1);
3347
return NodeStatus::RUNNING;
3448
}
3549

@@ -40,7 +54,7 @@ NodeStatus ReactiveFallback::tick()
4054

4155
case NodeStatus::SUCCESS:
4256
{
43-
haltChildren(0);
57+
halt();
4458
return NodeStatus::SUCCESS;
4559
}
4660

@@ -51,13 +65,12 @@ NodeStatus ReactiveFallback::tick()
5165
} // end switch
5266
} //end for
5367

54-
if( failure_count == childrenCount() )
68+
if( failure_count != childrenCount() )
5569
{
56-
haltChildren(0);
57-
return NodeStatus::FAILURE;
70+
throw LogicError("This is not supposed to happen");
5871
}
59-
60-
return NodeStatus::RUNNING;
72+
halt();
73+
return NodeStatus::FAILURE;
6174
}
6275

6376
}

src/controls/reactive_sequence.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ NodeStatus ReactiveSequence::tick()
2525
{
2626
is_asynch_child_.resize(childrenCount(), false);
2727
size_t success_count = 0;
28-
size_t running_count = 0;
2928

3029
for (size_t index = 0; index < childrenCount(); index++)
3130
{
3231
TreeNode* current_child_node = children_nodes_[index];
33-
if( is_asynch_child_[index] && current_child_node->status() == NodeStatus::SUCCESS )
32+
if( is_asynch_child_[index] &&
33+
current_child_node->status() == NodeStatus::SUCCESS )
3434
{
3535
success_count++;
3636
continue; // skip already executed asynch children
@@ -43,7 +43,6 @@ NodeStatus ReactiveSequence::tick()
4343
case NodeStatus::RUNNING:
4444
{
4545
is_asynch_child_[index] = true;
46-
running_count++;
4746
haltChildren(index+1);
4847
return NodeStatus::RUNNING;
4948
}
@@ -65,12 +64,12 @@ NodeStatus ReactiveSequence::tick()
6564
} // end switch
6665
} //end for
6766

68-
if( success_count == childrenCount())
67+
if( success_count != childrenCount())
6968
{
70-
halt();
71-
return NodeStatus::SUCCESS;
69+
throw LogicError("This is not supposed to happen");
7270
}
73-
return NodeStatus::RUNNING;
71+
halt();
72+
return NodeStatus::SUCCESS;
7473
}
7574

7675

tests/gtest_sequence.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ TEST_F(ReactiveSequenceTest, ReactiveSequence)
415415
ASSERT_EQ(NodeStatus::FAILURE, state);
416416
ASSERT_GE( elapsed_ms, 100 );
417417
ASSERT_LE( elapsed_ms, 120 );
418-
419418
}
420419

421420

0 commit comments

Comments
 (0)