crossdoor_nodes.cpp
Go to the documentation of this file.
1 #include "crossdoor_nodes.h"
2 
3 // This function must be implemented in the .cpp file to create
4 // a plugin that can be loaded at run-time
6 {
8 }
9 
10 // For simplicity, in this example the status of the door is not shared
11 // using ports and blackboards
12 static bool _door_open = false;
13 static bool _door_locked = true;
14 
16 {
17  SleepMS(500);
18  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
19 }
20 
22 {
23  SleepMS(500);
24  return _door_locked ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
25 }
26 
28 {
29  if( _door_locked )
30  {
31  SleepMS(2000);
32  _door_locked = false;
33  }
34  return NodeStatus::SUCCESS;
35 }
36 
38 {
39  SleepMS(1000);
40  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
41 }
42 
44 {
45  SleepMS(1000);
46  return NodeStatus::SUCCESS;
47 }
48 
50 {
51  if (_door_locked)
52  {
53  return NodeStatus::FAILURE;
54  }
55  SleepMS(2000);
56  _door_open = true;
57  return NodeStatus::SUCCESS;
58 }
59 
61 {
62  if (_door_open)
63  {
64  SleepMS(1500);
65  _door_open = false;
66  }
67  return NodeStatus::SUCCESS;
68 }
69 
70 // Register at once all the Actions and Conditions in this file
72 {
73  factory.registerSimpleCondition("IsDoorOpen", std::bind(IsDoorOpen));
74  factory.registerSimpleAction("PassThroughDoor", std::bind(PassThroughDoor));
75  factory.registerSimpleAction("PassThroughWindow", std::bind(PassThroughWindow));
76  factory.registerSimpleAction("OpenDoor", std::bind(OpenDoor));
77  factory.registerSimpleAction("CloseDoor", std::bind(CloseDoor));
78  factory.registerSimpleCondition("IsDoorLocked", std::bind(IsDoorLocked));
79  factory.registerSimpleAction("UnlockDoor", std::bind(UnlockDoor));
80 }
static bool _door_open
BT::NodeStatus IsDoorOpen()
BT::NodeStatus UnlockDoor()
void RegisterNodes(BT::BehaviorTreeFactory &factory)
void SleepMS(int ms)
Definition: movebase_node.h:12
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:207
BT::NodeStatus PassThroughDoor()
BT::NodeStatus IsDoorLocked()
BT::NodeStatus PassThroughWindow()
void registerSimpleAction(const std::string &ID, const SimpleActionNode::TickFunctor &tick_functor, PortsList ports={})
registerSimpleAction help you register nodes of type SimpleActionNode.
Definition: bt_factory.cpp:111
BT::NodeStatus CloseDoor()
NodeStatus
Definition: basic_types.h:35
static bool _door_locked
BT_REGISTER_NODES(factory)
BT::NodeStatus OpenDoor()
void registerSimpleCondition(const std::string &ID, const SimpleConditionNode::TickFunctor &tick_functor, PortsList ports={})
registerSimpleCondition help you register nodes of type SimpleConditionNode.
Definition: bt_factory.cpp:99


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