Skip to content

Commit c45c8ad

Browse files
committed
"fix" issue #587: ReactiveSequence should set conditions to IDLE
1 parent 02b3a27 commit c45c8ad

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

src/basic_types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ std::string toStr(NodeStatus status, bool colored)
5959
"RUNNING"
6060
"\x1b[0m"; // YELLOW
6161
case NodeStatus::SKIPPED:
62+
return "\x1b[34m"
63+
"SKIPPED"
64+
"\x1b[0m"; // BLUE
6265
case NodeStatus::IDLE:
6366
return "\x1b[36m"
6467
"IDLE"

src/controls/reactive_sequence.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ NodeStatus ReactiveSequence::tick()
3838
switch (child_status)
3939
{
4040
case NodeStatus::RUNNING: {
41-
// just in case, make sure that following children are not
42-
// in RUNNING state too
43-
for (size_t i = index + 1; i < childrenCount(); i++)
41+
// reset the previous children, to make sure that they are in IDLE state
42+
// the next time we tick them
43+
for (size_t i = 0; i < index; i++)
4444
{
4545
haltChild(i);
4646
}

tests/gtest_reactive.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#include <gtest/gtest.h>
22
#include "behaviortree_cpp/bt_factory.h"
33
#include "test_helper.hpp"
4+
#include "behaviortree_cpp/loggers/bt_cout_logger.h"
45

56
using BT::NodeStatus;
67
using std::chrono::milliseconds;
78

8-
static const char* reactive_xml_text = R"(
9+
TEST(Reactive, RunningChildren)
10+
{
11+
12+
static const char* reactive_xml_text = R"(
913
<root BTCPP_format="4" >
1014
<BehaviorTree ID="MainTree">
1115
<ReactiveSequence>
@@ -24,9 +28,6 @@ static const char* reactive_xml_text = R"(
2428
</root>
2529
)";
2630

27-
28-
TEST(Reactive, RunningChildren)
29-
{
3031
BT::BehaviorTreeFactory factory;
3132
std::array<int, 6> counters;
3233
RegisterTestTick(factory, "Test", counters);
@@ -56,3 +57,41 @@ TEST(Reactive, RunningChildren)
5657
}
5758

5859

60+
TEST(Reactive, Issue587)
61+
{
62+
// TestA should be executed only once, because of the variable "test"
63+
64+
static const char* reactive_xml_text = R"(
65+
<root BTCPP_format="4" >
66+
<BehaviorTree ID="Example A">
67+
<Sequence>
68+
<Script code="test := false"/>
69+
<ReactiveSequence>
70+
<RetryUntilSuccessful name="Retry 1" num_attempts="-1" _skipIf="test ">
71+
<TestA name="Success 1" _onSuccess="test = true"/>
72+
</RetryUntilSuccessful>
73+
<RetryUntilSuccessful name="Retry 2" num_attempts="5">
74+
<AlwaysFailure name="Failure 2"/>
75+
</RetryUntilSuccessful>
76+
</ReactiveSequence>
77+
</Sequence>
78+
</BehaviorTree>
79+
</root>
80+
)";
81+
82+
BT::BehaviorTreeFactory factory;
83+
std::array<int, 2> counters;
84+
RegisterTestTick(factory, "Test", counters);
85+
86+
auto tree = factory.createTreeFromText(reactive_xml_text);
87+
BT::StdCoutLogger logger(tree);
88+
89+
// for(int i=0; i<5; i++)
90+
{
91+
tree.tickWhileRunning();
92+
}
93+
94+
ASSERT_EQ(counters[0], 1);
95+
}
96+
97+

0 commit comments

Comments
 (0)