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 inline void SleepMS(int ms)
11 {
12  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
13 }
14 
15 // For simplicity, in this example the status of the door is not shared
16 // using ports and blackboards
17 static bool _door_open = false;
18 static bool _door_locked = true;
19 
21 {
22  SleepMS(500);
23  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
24 }
25 
27 {
28  SleepMS(500);
29  return _door_locked ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
30 }
31 
33 {
34  if( _door_locked )
35  {
36  SleepMS(2000);
37  _door_locked = false;
38  }
39  return NodeStatus::SUCCESS;
40 }
41 
43 {
44  SleepMS(1000);
45  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
46 }
47 
49 {
50  SleepMS(1000);
51  return NodeStatus::SUCCESS;
52 }
53 
55 {
56  if (_door_locked)
57  {
58  return NodeStatus::FAILURE;
59  }
60  SleepMS(2000);
61  _door_open = true;
62  return NodeStatus::SUCCESS;
63 }
64 
66 {
67  if (_door_open)
68  {
69  SleepMS(1500);
70  _door_open = false;
71  }
72  return NodeStatus::SUCCESS;
73 }
74 
75 // Register at once all the Actions and Conditions in this file
77 {
78  factory.registerSimpleCondition("IsDoorOpen", std::bind(IsDoorOpen));
79  factory.registerSimpleAction("PassThroughDoor", std::bind(PassThroughDoor));
80  factory.registerSimpleAction("PassThroughWindow", std::bind(PassThroughWindow));
81  factory.registerSimpleAction("OpenDoor", std::bind(OpenDoor));
82  factory.registerSimpleAction("CloseDoor", std::bind(CloseDoor));
83  factory.registerSimpleCondition("IsDoorLocked", std::bind(IsDoorLocked));
84  factory.registerSimpleAction("UnlockDoor", std::bind(UnlockDoor));
85 }
static bool _door_open
BT::NodeStatus IsDoorOpen()
BT::NodeStatus UnlockDoor()
void RegisterNodes(BT::BehaviorTreeFactory &factory)
void SleepMS(int ms)
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:251
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:117
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:104


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Mon Jul 3 2023 02:50:14