33 auto queue = std::make_shared<ProtectedQueue<Pose2D>>();
34 for (
int i = 0; i < 10; i++)
36 queue->items.push_back(
Pose2D{double(i), double(i), 0});
38 setOutput(
"waypoints", queue);
44 return {OutputPort<std::shared_ptr<ProtectedQueue<Pose2D>>>(
"waypoints")};
57 std::shared_ptr<ProtectedQueue<Pose2D>> queue;
58 if (getInput(
"waypoints", queue) && queue)
66 std::unique_lock<std::mutex> lk(queue->mtx);
68 auto& waypoints = queue->items;
69 if (waypoints.empty())
73 wp = waypoints.front();
74 waypoints.pop_front();
78 std::this_thread::sleep_for(std::chrono::milliseconds(100));
79 std::cout <<
"Using waypoint: " << wp.
x <<
"/" << wp.
y << std::endl;
91 return {InputPort<std::shared_ptr<ProtectedQueue<Pose2D>>>(
"waypoints")};
108 if (getInput(
"waypoint", wp))
110 std::this_thread::sleep_for(std::chrono::milliseconds(100));
111 std::cout <<
"Using waypoint: " << wp.
x <<
"/" << wp.
y << std::endl;
122 return {InputPort<Pose2D>(
"waypoint")};
129 <root main_tree_to_execute = "TreeImplicit" > 130 <BehaviorTree ID="TreeImplicit"> 132 <GenerateWaypoints waypoints="{waypoints}" /> 133 <KeepRunningUntilFailure> 134 <UseWaypointQueue waypoints="{waypoints}" /> 135 </KeepRunningUntilFailure> 143 <root main_tree_to_execute = "TreeA" > 144 <BehaviorTree ID="TreeA"> 146 <GenerateWaypoints waypoints="{waypoints}" /> 147 <QueueSize queue="{waypoints}" size="{wp_size}" /> 148 <Repeat num_cycles="{wp_size}" > 150 <PopFromQueue queue="{waypoints}" popped_item="{wp}" /> 151 <UseWaypoint waypoint="{wp}" /> 160 <root main_tree_to_execute = "TreeB" > 161 <BehaviorTree ID="TreeB"> 163 <GenerateWaypoints waypoints="{waypoints}" /> 164 <ConsumeQueue queue="{waypoints}" popped_item="{wp}"> 165 <UseWaypoint waypoint="{wp}" /> 191 tree.
sleep(std::chrono::milliseconds(10));
193 std::cout <<
"--------------" << std::endl;
void sleep(std::chrono::system_clock::duration timeout)
static PortsList providedPorts()
void registerNodeType(const std::string &ID)
static const char * xml_A
GenerateWaypoints(const std::string &name, const NodeConfiguration &config)
The AsyncActionNode uses a different thread, where the action will be executed.
static const char * xml_text
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
NodeStatus tick() override
Method to be implemented by the user.
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
NodeStatus tick() override
Method to be implemented by the user.
static const char * xml_B
UseWaypoint(const std::string &name, const NodeConfiguration &config)
std::unordered_map< std::string, PortInfo > PortsList
Dummy action that generates a list of poses.
static PortsList providedPorts()
static const char * xml_implicit
static PortsList providedPorts()
UseWaypointQueue(const std::string &name, const NodeConfiguration &config)
Simple Action that uses the output of PopFromQueue<Pose2D> or ConsumeQueue<Pose2D> ...
NodeStatus tick() override
Method to be implemented by the user.