BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
sleep_node.h
1#pragma once
2
3#include "behaviortree_cpp/action_node.h"
4#include "behaviortree_cpp/utils/timer_queue.h"
5
6#include <atomic>
7
8namespace BT
9{
10/**
11 * @brief Sleep for a certain amount of time.
12 * Consider also using the decorator <Delay/>
13 *
14 * <Sleep msec="5000"/>
15 */
16class SleepNode : public StatefulActionNode
17{
18public:
19 SleepNode(const std::string& name, const NodeConfig& config);
20
21 ~SleepNode() override
22 {
23 halt();
24 }
25
26 SleepNode(const SleepNode&) = delete;
27 SleepNode& operator=(const SleepNode&) = delete;
28 SleepNode(SleepNode&&) = delete;
29 SleepNode& operator=(SleepNode&&) = delete;
30
31 NodeStatus onStart() override;
32
33 NodeStatus onRunning() override;
34
35 void onHalted() override;
36
37 static PortsList providedPorts()
38 {
39 return { InputPort<unsigned>("msec") };
40 }
41
42private:
43 TimerQueue<> timer_;
44 uint64_t timer_id_ = 0;
45
46 std::atomic_bool timer_waiting_ = false;
47 std::mutex delay_mutex_;
48};
49
50} // namespace BT
Sleep for a certain amount of time. Consider also using the decorator <Delay>
Definition: sleep_node.h:17
NodeStatus onStart() override
void onHalted() override
NodeStatus onRunning() override
method invoked when the action is already in the RUNNING state.
The StatefulActionNode is the preferred way to implement asynchronous Actions. It is actually easier ...
Definition: action_node.h:174
void halt() override final
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34
Definition: tree_node.h:105