Skip to content

Commit 24a3ce1

Browse files
committed
Control node and Decorators RUNNING before first child
1 parent c0558d4 commit 24a3ce1

18 files changed

+86
-50
lines changed

include/behaviortree_cpp/controls/fallback_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class FallbackNode : public ControlNode
4040

4141
private:
4242
size_t current_child_idx_;
43+
bool all_skipped_ = true;
4344

4445
virtual BT::NodeStatus tick() override;
4546
};

include/behaviortree_cpp/controls/parallel_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class ParallelNode : public ControlNode
6767
int failure_threshold_;
6868

6969
std::set<size_t> skip_list_;
70+
bool all_skipped_ = true;
7071

7172
bool read_parameter_from_ports_;
7273
static constexpr const char* THRESHOLD_SUCCESS = "success_count";

include/behaviortree_cpp/controls/sequence_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SequenceNode : public ControlNode
4141

4242
private:
4343
size_t current_child_idx_;
44+
bool all_skipped_ = true;
4445

4546
virtual BT::NodeStatus tick() override;
4647
};

include/behaviortree_cpp/controls/sequence_star_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SequenceWithMemory : public ControlNode
4242

4343
private:
4444
size_t current_child_idx_;
45+
bool all_skipped_ = true;
4546

4647
virtual BT::NodeStatus tick() override;
4748
};

include/behaviortree_cpp/decorators/delay_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DelayNode : public DecoratorNode
4949
virtual BT::NodeStatus tick() override;
5050

5151
bool delay_started_;
52-
bool delay_complete_;
52+
std::atomic_bool delay_complete_;
5353
bool delay_aborted_;
5454
unsigned msec_;
5555
bool read_parameter_from_ports_;

include/behaviortree_cpp/decorators/repeat_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class RepeatNode : public DecoratorNode
5050
private:
5151
int num_cycles_;
5252
int repeat_count_;
53+
bool all_skipped_ = true;
5354

5455
bool read_parameter_from_ports_;
5556
static constexpr const char* NUM_CYCLES = "num_cycles";

include/behaviortree_cpp/decorators/retry_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class RetryNode : public DecoratorNode
5656
private:
5757
int max_attempts_;
5858
int try_count_;
59+
bool all_skipped_ = true;
5960

6061
bool read_parameter_from_ports_;
6162
static constexpr const char* NUM_ATTEMPTS = "num_attempts";

include/behaviortree_cpp/decorators/subtree_node.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,26 @@ class SubTreeNode : public DecoratorNode
5656

5757
static PortsList providedPorts();
5858

59-
private:
59+
void setSubtreeID(const std::string& ID)
60+
{
61+
subtree_id_ = ID;
62+
}
63+
64+
const std::string& subtreeID() const
65+
{
66+
return subtree_id_;
67+
}
6068
virtual BT::NodeStatus tick() override;
6169

6270
virtual NodeType type() const override final
6371
{
6472
return NodeType::SUBTREE;
6573
}
74+
75+
76+
private:
77+
std::string subtree_id_;
78+
6679
};
6780

6881
} // namespace BT

src/controls/fallback_node.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace BT
1717
{
1818
FallbackNode::FallbackNode(const std::string& name) :
19-
ControlNode::ControlNode(name, {}), current_child_idx_(0)
19+
ControlNode::ControlNode(name, {}), current_child_idx_(0), all_skipped_(true)
2020
{
2121
setRegistrationID("Fallback");
2222
}
@@ -25,6 +25,13 @@ NodeStatus FallbackNode::tick()
2525
{
2626
const size_t children_count = children_nodes_.size();
2727

28+
if(status() == NodeStatus::IDLE)
29+
{
30+
all_skipped_ = true;
31+
}
32+
33+
setStatus(NodeStatus::RUNNING);
34+
2835
while (current_child_idx_ < children_count)
2936
{
3037
TreeNode* current_child_node = children_nodes_[current_child_idx_];
@@ -33,10 +40,7 @@ NodeStatus FallbackNode::tick()
3340
const NodeStatus child_status = current_child_node->executeTick();
3441

3542
// switch to RUNNING state as soon as you find an active child
36-
if (child_status != NodeStatus::SKIPPED)
37-
{
38-
setStatus(NodeStatus::RUNNING);
39-
}
43+
all_skipped_ &= (child_status == NodeStatus::SKIPPED);
4044

4145
switch (child_status)
4246
{
@@ -79,7 +83,7 @@ NodeStatus FallbackNode::tick()
7983
}
8084

8185
// Skip if ALL the nodes have been skipped
82-
return status() == (NodeStatus::RUNNING) ? NodeStatus::FAILURE : NodeStatus::SKIPPED;
86+
return all_skipped_ ? NodeStatus::SKIPPED : NodeStatus::FAILURE;
8387
}
8488

8589
void FallbackNode::halt()

src/controls/parallel_node.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ NodeStatus ParallelNode::tick()
6767
throw LogicError("Number of children is less than threshold. Can never fail.");
6868
}
6969

70+
if(status() == NodeStatus::IDLE)
71+
{
72+
all_skipped_ = true;
73+
}
74+
setStatus(NodeStatus::RUNNING);
75+
7076
// Routing the tree according to the sequence node's logic:
7177
for (size_t i = 0; i < children_count; i++)
7278
{
@@ -79,10 +85,7 @@ NodeStatus ParallelNode::tick()
7985
in_skip_list ? prev_status : child_node->executeTick();
8086

8187
// switch to RUNNING state as soon as you find an active child
82-
if (child_status != NodeStatus::SKIPPED)
83-
{
84-
setStatus(NodeStatus::RUNNING);
85-
}
88+
all_skipped_ &= (child_status == NodeStatus::SKIPPED);
8689

8790
switch (child_status)
8891
{
@@ -131,7 +134,7 @@ NodeStatus ParallelNode::tick()
131134
}
132135
}
133136
// Skip if ALL the nodes have been skipped
134-
return status() == (NodeStatus::RUNNING) ? NodeStatus::RUNNING : NodeStatus::SKIPPED;
137+
return all_skipped_ ? NodeStatus::SKIPPED : NodeStatus::RUNNING;
135138
}
136139

137140
void ParallelNode::halt()

0 commit comments

Comments
 (0)