crossdoor_nodes.cpp
Go to the documentation of this file.
1 #include "crossdoor_nodes.h"
2 
3 inline void SleepMS(int ms)
4 {
5  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
6 }
7 
8 using BT::NodeStatus;
9 
11 {
12  SleepMS(200);
13  return !_door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
14 }
15 
17 {
18  SleepMS(500);
19  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
20 }
21 
23 {
24  SleepMS(500);
25  if(_door_locked)
26  {
27  return NodeStatus::FAILURE;
28  }
29  else
30  {
31  _door_open = true;
32  return NodeStatus::SUCCESS;
33  }
34 }
35 
37 {
38  SleepMS(500);
39  // succeed at 3rd attempt
40  if(_pick_attempts++ > 3)
41  {
42  _door_locked = false;
43  _door_open = true;
44  }
45  return _door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
46 }
47 
49 {
50  _door_locked = false;
51  _door_open = true;
52  // smash always works
53  return NodeStatus::SUCCESS;
54 }
55 
57 {
58  factory.registerSimpleCondition("IsDoorClosed",
60 
61  factory.registerSimpleAction("PassThroughDoor",
63 
64  factory.registerSimpleAction("OpenDoor", std::bind(&CrossDoor::openDoor, this));
65 
66  factory.registerSimpleAction("PickLock", std::bind(&CrossDoor::pickLock, this));
67 
68  factory.registerSimpleCondition("SmashDoor", std::bind(&CrossDoor::smashDoor, this));
69 }
70 
72 {
73  _door_open = false;
74  _door_locked = true;
75  _pick_attempts = 0;
76 }
77 
78 // This function must be implemented in the .cpp file to create
79 // a plugin that can be loaded at run-time
81 {
82  static CrossDoor cross_door;
83  cross_door.registerNodes(factory);
84 }
CrossDoor::smashDoor
BT::NodeStatus smashDoor()
Definition: crossdoor_nodes.cpp:48
CrossDoor::_pick_attempts
int _pick_attempts
Definition: crossdoor_nodes.h:30
CrossDoor::reset
void reset()
Definition: crossdoor_nodes.cpp:71
lexy::bind
constexpr auto bind(Callback &&callback, BoundArgs &&... args)
Binds the operator() of the callback with pre-defined/remapped values.
Definition: bind.hpp:321
CrossDoor::registerNodes
void registerNodes(BT::BehaviorTreeFactory &factory)
Definition: crossdoor_nodes.cpp:56
CrossDoor::openDoor
BT::NodeStatus openDoor()
Definition: crossdoor_nodes.cpp:22
CrossDoor::passThroughDoor
BT::NodeStatus passThroughDoor()
Definition: crossdoor_nodes.cpp:16
SleepMS
void SleepMS(int ms)
Definition: crossdoor_nodes.cpp:3
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:205
crossdoor_nodes.h
CrossDoor::pickLock
BT::NodeStatus pickLock()
Definition: crossdoor_nodes.cpp:36
CrossDoor
Definition: crossdoor_nodes.h:5
CrossDoor::isDoorClosed
BT::NodeStatus isDoorClosed()
Definition: crossdoor_nodes.cpp:10
BT_REGISTER_NODES
BT_REGISTER_NODES(factory)
Definition: crossdoor_nodes.cpp:80
CrossDoor::_door_locked
bool _door_locked
Definition: crossdoor_nodes.h:29
BT::BehaviorTreeFactory::registerSimpleCondition
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:153
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
CrossDoor::_door_open
bool _door_open
Definition: crossdoor_nodes.h:28
BT::BehaviorTreeFactory::registerSimpleAction
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:166


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Sun Sep 22 2024 02:19:15