sleep_node.cpp
Go to the documentation of this file.
2 
3 namespace BT
4 {
5 
6 SleepNode::SleepNode(const std::string& name, const NodeConfig& config)
7  : StatefulActionNode(name, config), timer_waiting_(false)
8 {}
9 
11 {
12  unsigned msec = 0;
13  if(!getInput("msec", msec))
14  {
15  throw RuntimeError("Missing parameter [msec] in SleepNode");
16  }
17 
18  if(msec <= 0)
19  {
20  return NodeStatus::SUCCESS;
21  }
22 
24 
25  timer_waiting_ = true;
26 
27  timer_id_ = timer_.add(std::chrono::milliseconds(msec), [this](bool aborted) {
28  std::unique_lock<std::mutex> lk(delay_mutex_);
29  if(!aborted)
30  {
32  }
33  timer_waiting_ = false;
34  });
35 
36  return NodeStatus::RUNNING;
37 }
38 
40 {
42 }
43 
45 {
46  timer_waiting_ = false;
48 }
49 
50 } // namespace BT
BT::TreeNode::getInput
Result getInput(const std::string &key, T &destination) const
Definition: tree_node.h:547
BT
Definition: ex01_wrap_legacy.cpp:29
BT::SleepNode::SleepNode
SleepNode(const std::string &name, const NodeConfig &config)
Definition: sleep_node.cpp:6
BT::TimerQueue::add
uint64_t add(std::chrono::milliseconds milliseconds, std::function< void(bool)> handler)
Adds a new timer.
Definition: timer_queue.h:92
BT::SleepNode::onRunning
NodeStatus onRunning() override
method invoked when the action is already in the RUNNING state.
Definition: sleep_node.cpp:39
BT::TreeNode::emitWakeUpSignal
void emitWakeUpSignal()
Notify that the tree should be ticked again()
Definition: tree_node.cpp:420
BT::SleepNode::onStart
NodeStatus onStart() override
Definition: sleep_node.cpp:10
sleep_node.h
BT::SleepNode::onHalted
void onHalted() override
Definition: sleep_node.cpp:44
BT::SleepNode::timer_id_
uint64_t timer_id_
Definition: sleep_node.h:38
BT::TimerQueue::cancel
size_t cancel(uint64_t id)
Cancels the specified timer.
Definition: timer_queue.h:114
BT::TreeNode::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: tree_node.cpp:154
BT::RuntimeError
Definition: exceptions.h:58
BT::NodeStatus::SUCCESS
@ SUCCESS
BT::SleepNode::timer_waiting_
std::atomic_bool timer_waiting_
Definition: sleep_node.h:40
BT::NodeStatus::RUNNING
@ RUNNING
BT::SleepNode::delay_mutex_
std::mutex delay_mutex_
Definition: sleep_node.h:41
BT::NodeConfig
Definition: tree_node.h:73
BT::SleepNode::timer_
TimerQueue timer_
Definition: sleep_node.h:37
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
BT::StatefulActionNode
The StatefulActionNode is the preferred way to implement asynchronous Actions. It is actually easier ...
Definition: action_node.h:159


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:08