run_once_node.h
Go to the documentation of this file.
1 /* Copyright (C) 2023 Davide Faconti - All Rights Reserved
2 * Copyright (C) 2022 Gaël Écorchard, Czech Institute of Informatics, Robotics, and Cybernetics (ciirc) <gael.ecorchard@cvut.cz>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * 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:
7 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * 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,
11 * 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.
12 */
13 
14 #pragma once
15 
17 
18 namespace BT
19 {
20 
32 class RunOnceNode : public DecoratorNode
33 {
34 public:
35  RunOnceNode(const std::string& name, const NodeConfig& config)
37  {
38  setRegistrationID("RunOnce");
39  }
40 
42  {
43  return { InputPort<bool>("then_skip", true,
44  "If true, skip after the first execution, "
45  "otherwise return the same NodeStatus returned once bu the "
46  "child.") };
47  }
48 
49 private:
50  virtual BT::NodeStatus tick() override;
51 
52  bool already_ticked_ = false;
54 };
55 
56 //------------ implementation ----------------------------
57 
59 {
60  bool skip = true;
61  if(auto const res = getInput<bool>("then_skip"))
62  {
63  skip = res.value();
64  }
65 
66  if(already_ticked_)
67  {
68  return skip ? NodeStatus::SKIPPED : returned_status_;
69  }
70 
73 
75  {
76  already_ticked_ = true;
78  resetChild();
79  }
80  return status;
81 }
82 
83 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::RunOnceNode::returned_status_
NodeStatus returned_status_
Definition: run_once_node.h:53
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:345
BT::TreeNode::executeTick
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:71
BT::DecoratorNode
Definition: decorator_node.h:8
BT::RunOnceNode::providedPorts
static PortsList providedPorts()
Definition: run_once_node.h:41
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::TreeNode::status
NodeStatus status() const
Definition: tree_node.cpp:279
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::NodeStatus::SKIPPED
@ SKIPPED
BT::TreeNode::setRegistrationID
void setRegistrationID(StringView ID)
Definition: tree_node.cpp:433
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
BT::NodeStatus::RUNNING
@ RUNNING
BT::isStatusCompleted
bool isStatusCompleted(const NodeStatus &status)
Definition: basic_types.h:47
BT::RunOnceNode::RunOnceNode
RunOnceNode(const std::string &name, const NodeConfig &config)
Definition: run_once_node.h:35
BT::RunOnceNode::tick
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: run_once_node.h:58
BT::NodeStatus::IDLE
@ IDLE
BT::NodeConfig
Definition: tree_node.h:73
BT::DecoratorNode::resetChild
void resetChild()
Definition: decorator_node.cpp:53
BT::RunOnceNode::already_ticked_
bool already_ticked_
Definition: run_once_node.h:52
decorator_node.h
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
BT::DecoratorNode::child_node_
TreeNode * child_node_
Definition: decorator_node.h:11
BT::RunOnceNode
The RunOnceNode is used when you want to execute the child only once. If the child is asynchronous,...
Definition: run_once_node.h:32


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