Skip to content

Commit 692ab36

Browse files
committed
fix issue #621: ConsumeQueue
1 parent 2341397 commit 692ab36

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

examples/ex04_waypoints.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ using namespace BT;
88
/*
99
* In this example we will show how a common design pattern could be implemented.
1010
* We want to iterate through the elements of a queue, for instance a list of waypoints.
11-
*
12-
* Two ways to create a "loop" are presented, one using the actions "QueueSize" and "PopFromQueue"
13-
* and the other using the decorator "ConsumeQueue".
1411
*/
1512

1613
struct Pose2D

include/behaviortree_cpp/decorators/consume_queue.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ namespace BT
2525
*
2626
* An empty queue will return SUCCESS
2727
*/
28+
29+
2830
template <typename T>
29-
class ConsumeQueue : public DecoratorNode
31+
class [[deprecated("You are encouraged to use the LoopNode instead")]]
32+
ConsumeQueue : public DecoratorNode
3033
{
3134
public:
3235
ConsumeQueue(const std::string& name, const NodeConfig& config) :
@@ -35,6 +38,9 @@ class ConsumeQueue : public DecoratorNode
3538

3639
NodeStatus tick() override
3740
{
41+
// by default, return SUCCESS, even if queue is empty
42+
NodeStatus status_to_be_returned = NodeStatus::SUCCESS;
43+
3844
if (running_child_)
3945
{
4046
NodeStatus child_state = child_node_->executeTick();
@@ -46,6 +52,7 @@ class ConsumeQueue : public DecoratorNode
4652
else
4753
{
4854
haltChild();
55+
status_to_be_returned = child_state;
4956
}
5057
}
5158

@@ -79,18 +86,18 @@ class ConsumeQueue : public DecoratorNode
7986
{
8087
return NodeStatus::FAILURE;
8188
}
89+
status_to_be_returned = child_state;
8290
}
8391
}
8492
}
8593

86-
return NodeStatus::SUCCESS;
94+
return status_to_be_returned;
8795
}
8896

8997
static PortsList providedPorts()
9098
{
91-
return {InputPort<std::shared_ptr<ProtectedQueue<T>>>("queue"), OutputPort<T>("popped"
92-
"_ite"
93-
"m")};
99+
return {InputPort<std::shared_ptr<ProtectedQueue<T>>>("queue"),
100+
OutputPort<T>("popped_item")};
94101
}
95102

96103
private:

0 commit comments

Comments
 (0)