blackboard_precondition.h
Go to the documentation of this file.
1 /* Copyright (C) 2018-2020 Davide Faconti, Eurecat - 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 #ifndef DECORATOR_BLACKBOARD_PRECONDITION_NODE_H
14 #define DECORATOR_BLACKBOARD_PRECONDITION_NODE_H
15 
17 
18 namespace BT
19 {
32 template <typename T>
34 {
35  public:
37  : DecoratorNode(name, config)
38  {
39  if( std::is_same<T,int>::value)
40  setRegistrationID("BlackboardCheckInt");
41  else if( std::is_same<T,double>::value)
42  setRegistrationID("BlackboardCheckDouble");
43  else if( std::is_same<T,std::string>::value)
44  setRegistrationID("BlackboardCheckString");
45  }
46 
47  virtual ~BlackboardPreconditionNode() override = default;
48 
50  {
51  return {InputPort("value_A"),
52  InputPort("value_B"),
53  InputPort<NodeStatus>("return_on_mismatch") };
54  }
55 
56  private:
57  virtual BT::NodeStatus tick() override;
58 };
59 
60 //----------------------------------------------------
61 
62 template<typename T> inline
64 {
65  T value_A;
66  T value_B;
67  NodeStatus default_return_status = NodeStatus::FAILURE;
68 
70 
71  if( getInput("value_A", value_A) &&
72  getInput("value_B", value_B) &&
73  value_B == value_A )
74  {
75  return child_node_->executeTick();
76  }
77 
78  if( child()->status() == NodeStatus::RUNNING )
79  {
80  haltChild();
81  }
82  getInput("return_on_mismatch", default_return_status);
83  return default_return_status;
84 }
85 
86 } // end namespace
87 
88 #endif
virtual ~BlackboardPreconditionNode() override=default
const TreeNode * child() const
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
const NodeConfiguration & config() const
Definition: tree_node.cpp:99
TreeNode * child_node_
void haltChild()
Halt() the child node.
Result getInput(const std::string &key, T &destination) const
Definition: tree_node.h:192
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:317
void setRegistrationID(StringView ID)
Definition: tree_node.h:163
NodeStatus status() const
Definition: tree_node.cpp:56
NodeStatus
Definition: basic_types.h:35
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:33
std::pair< std::string, PortInfo > InputPort(StringView name, StringView description={})
Definition: basic_types.h:283
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:40
BlackboardPreconditionNode(const std::string &name, const NodeConfiguration &config)


behaviotree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Tue May 4 2021 02:56:24