delay_node.h
Go to the documentation of this file.
1 /* Copyright (C) 2018-2023 Davide Faconti - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #pragma once
14 
17 #include <atomic>
18 
19 namespace BT
20 {
34 class DelayNode : public DecoratorNode
35 {
36 public:
37  DelayNode(const std::string& name, unsigned milliseconds);
38 
39  DelayNode(const std::string& name, const NodeConfig& config);
40 
41  ~DelayNode() override
42  {
43  halt();
44  }
45 
47  {
48  return { InputPort<unsigned>("delay_msec", "Tick the child after a few "
49  "milliseconds") };
50  }
51 
52  void halt() override;
53 
54 private:
56  uint64_t timer_id_;
57 
58  virtual BT::NodeStatus tick() override;
59 
60  bool delay_started_ = false;
61  std::atomic_bool delay_complete_ = false;
62  bool delay_aborted_ = false;
63  unsigned msec_;
66 };
67 
68 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::TimerQueue
Definition: timer_queue.h:72
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:345
BT::DelayNode::tick
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: delay_node.cpp:33
BT::DecoratorNode
Definition: decorator_node.h:8
timer_queue.h
BT::DelayNode::delay_aborted_
bool delay_aborted_
Definition: delay_node.h:62
BT::DelayNode::DelayNode
DelayNode(const std::string &name, unsigned milliseconds)
Definition: delay_node.cpp:8
mutex
static pthread_mutex_t mutex
Definition: minitrace.cpp:77
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::DelayNode::delay_started_
bool delay_started_
Definition: delay_node.h:60
BT::DelayNode::read_parameter_from_ports_
bool read_parameter_from_ports_
Definition: delay_node.h:64
BT::DelayNode::halt
void halt() override
The method used to interrupt the execution of this node.
Definition: delay_node.cpp:26
BT::DelayNode::timer_
TimerQueue timer_
Definition: delay_node.h:55
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
BT::DelayNode
The delay node will introduce a delay and then tick the child returning the status of the child as it...
Definition: delay_node.h:34
BT::DelayNode::timer_id_
uint64_t timer_id_
Definition: delay_node.h:56
BT::DelayNode::msec_
unsigned msec_
Definition: delay_node.h:63
BT::DelayNode::delay_complete_
std::atomic_bool delay_complete_
Definition: delay_node.h:61
BT::NodeConfig
Definition: tree_node.h:73
BT::DelayNode::~DelayNode
~DelayNode() override
Definition: delay_node.h:41
decorator_node.h
BT::DelayNode::delay_mutex_
std::mutex delay_mutex_
Definition: delay_node.h:65
BT::DelayNode::providedPorts
static PortsList providedPorts()
Definition: delay_node.h:46
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33


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