2
3
4
5
6
7
8
9
10
11
15#include "behaviortree_cpp/decorator_node.h"
29
30
31
32
33
34
35
36
37
38template <
typename T =
Any>
41 bool child_running_ =
false;
42 SharedQueue<T> static_queue_;
43 SharedQueue<T> current_queue_;
46 LoopNode(
const std::string& name,
const NodeConfig& config)
49 auto raw_port = getRawPortValue(
"queue");
50 if(!isBlackboardPointer(raw_port))
52 static_queue_ = convertFromString<SharedQueue<T>>(raw_port);
61 child_running_ =
false;
65 current_queue_ = std::make_shared<std::deque<T>>();
66 *current_queue_ = *static_queue_;
75 AnyPtrLocked any_ref =
76 static_queue_ ? AnyPtrLocked() : getLockedPortContent(
"queue");
82 auto queue_result = any_ref.get()->tryCast<SharedQueue<T>>();
85 current_queue_ = queue_result.value();
87 else if(!current_queue_)
91 auto vec_result = any_ref.get()->tryCast<std::vector<T>>();
95 const auto& vec = vec_result.value();
96 current_queue_ = std::make_shared<std::deque<T>>(vec.begin(), vec.end());
98 else if(any_ref.get()->isString())
101 auto str = any_ref.get()->cast<std::string>();
102 current_queue_ = convertFromString<SharedQueue<T>>(str);
106 throw RuntimeError(
"LoopNode: port 'queue' must contain either "
107 "SharedQueue<T>, std::vector<T>, or a string");
112 if(current_queue_ && !current_queue_->empty())
114 auto value = std::move(current_queue_->front());
115 current_queue_->pop_front();
117 setOutput(
"value", value);
121 if(!popped && !child_running_)
123 return getInput<
NodeStatus>(
"if_empty").value();
132 child_running_ = (child_state ==
NodeStatus::RUNNING);
134 if(isStatusCompleted(child_state))
146 static PortsList providedPorts()
150 return { BidirectionalPort(
"queue"),
152 "Status to return if queue is empty: "
153 "SUCCESS, FAILURE, SKIPPED"),
154 OutputPort<T>(
"value") };
Definition: safe_any.hpp:50
The DecoratorNode is the base class for nodes that have exactly one child.
Definition: decorator_node.h:19
The LoopNode class is used to pop_front elements from a std::deque. This element is copied into the p...
Definition: loop_node.h:40
NodeStatus tick() override
Method to be implemented by the user.
Definition: loop_node.h:56
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
void setStatus(NodeStatus new_status)
setStatus changes the status of the node. it will throw if you try to change the status to IDLE,...
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34
Definition: tree_node.h:105