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;
62 current_queue_.reset();
67 current_queue_ = std::make_shared<std::deque<T>>();
68 *current_queue_ = *static_queue_;
77 AnyPtrLocked any_ref =
78 static_queue_ ? AnyPtrLocked() : getLockedPortContent(
"queue");
84 auto queue_result = any_ref.get()->tryCast<SharedQueue<T>>();
87 current_queue_ = queue_result.value();
89 else if(!current_queue_)
93 auto vec_result = any_ref.get()->tryCast<std::vector<T>>();
97 const auto& vec = vec_result.value();
98 current_queue_ = std::make_shared<std::deque<T>>(vec.begin(), vec.end());
100 else if(any_ref.get()->isString())
103 auto str = any_ref.get()->cast<std::string>();
104 current_queue_ = convertFromString<SharedQueue<T>>(str);
108 throw RuntimeError(
"LoopNode: port 'queue' must contain either "
109 "SharedQueue<T>, std::vector<T>, or a string");
114 if(current_queue_ && !current_queue_->empty())
116 auto value = std::move(current_queue_->front());
117 current_queue_->pop_front();
119 setOutput(
"value", value);
123 if(!popped && !child_running_)
125 return getInput<
NodeStatus>(
"if_empty").value();
134 child_running_ = (child_state ==
NodeStatus::RUNNING);
136 if(isStatusCompleted(child_state))
148 static PortsList providedPorts()
152 return { BidirectionalPort(
"queue"),
154 "Status to return if queue is empty: "
155 "SUCCESS, FAILURE, SKIPPED"),
156 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