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  SleepMS(2000);
30  _door_locked = false;
31  return NodeStatus::SUCCESS;
32 }
33 
35 {
36  SleepMS(1000);
37  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
38 }
39 
41 {
42  SleepMS(1000);
43  return NodeStatus::SUCCESS;
44 }
45 
47 {
48  if (_door_locked)
49  {
50  SleepMS(2000);
51  _door_open = true;
52  }
53 
54  return NodeStatus::SUCCESS;
55 }
56 
58 {
59  if (_door_open)
60  {
61  SleepMS(1500);
62  _door_open = false;
63  }
64  return NodeStatus::SUCCESS;
65 }
66 
67 // Register at once all the Actions and Conditions in this file
69 {
70  factory.registerSimpleCondition("IsDoorOpen", std::bind(IsDoorOpen));
71  factory.registerSimpleAction("PassThroughDoor", std::bind(PassThroughDoor));
72  factory.registerSimpleAction("PassThroughWindow", std::bind(PassThroughWindow));
73  factory.registerSimpleAction("OpenDoor", std::bind(OpenDoor));
74  factory.registerSimpleAction("CloseDoor", std::bind(CloseDoor));
75  factory.registerSimpleCondition("IsDoorLocked", std::bind(IsDoorLocked));
76  factory.registerSimpleAction("UnlockDoor", std::bind(UnlockDoor));
77 }
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:98
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:92
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:80


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04