crossdoor_nodes.cpp
Go to the documentation of this file.
00001 #include "crossdoor_nodes.h"
00002 
00003 // This function must be implemented in the .cpp file to create
00004 // a plugin that can be loaded at run-time
00005 BT_REGISTER_NODES(factory)
00006 {
00007     CrossDoor::RegisterNodes(factory);
00008 }
00009 
00010 NodeStatus CrossDoor::IsDoorOpen(TreeNode& self)
00011 {
00012     SleepMS(500);
00013     bool door_open = self.blackboard()->get<bool>("door_open");
00014 
00015     return door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
00016 }
00017 
00018 NodeStatus CrossDoor::IsDoorLocked(TreeNode& self)
00019 {
00020     SleepMS(500);
00021     bool door_locked = self.blackboard()->get<bool>("door_locked");
00022 
00023     return door_locked ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
00024 }
00025 
00026 NodeStatus CrossDoor::UnlockDoor(TreeNode& self)
00027 {
00028     SleepMS(2000);
00029     self.blackboard()->set("door_locked", false);
00030 
00031     return NodeStatus::SUCCESS;
00032 }
00033 
00034 NodeStatus CrossDoor::PassThroughDoor(TreeNode& self)
00035 {
00036     SleepMS(1000);
00037     bool door_open = self.blackboard()->get<bool>("door_open");
00038 
00039     return door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
00040 }
00041 
00042 NodeStatus CrossDoor::PassThroughWindow(TreeNode& self)
00043 {
00044     SleepMS(1000);
00045     return NodeStatus::SUCCESS;
00046 }
00047 
00048 NodeStatus CrossDoor::OpenDoor(TreeNode& self)
00049 {
00050     SleepMS(2000);
00051     bool door_locked = self.blackboard()->get<bool>("door_locked");
00052 
00053     if (door_locked)
00054     {
00055         return NodeStatus::FAILURE;
00056     }
00057 
00058     self.blackboard()->set("door_open", true);
00059     return NodeStatus::SUCCESS;
00060 }
00061 
00062 NodeStatus CrossDoor::CloseDoor(TreeNode& self)
00063 {
00064     bool door_open = self.blackboard()->get<bool>("door_open");
00065 
00066     if (door_open)
00067     {
00068         SleepMS(1500);
00069         self.blackboard()->set("door_open", false);
00070     }
00071     return NodeStatus::SUCCESS;
00072 }
00073 
00074 void CrossDoor::RegisterNodes(BehaviorTreeFactory& factory)
00075 {
00076     factory.registerSimpleCondition("IsDoorOpen", IsDoorOpen);
00077     factory.registerSimpleAction("PassThroughDoor", PassThroughDoor);
00078     factory.registerSimpleAction("PassThroughWindow", PassThroughWindow);
00079     factory.registerSimpleAction("OpenDoor", OpenDoor);
00080     factory.registerSimpleAction("CloseDoor", CloseDoor);
00081     factory.registerSimpleCondition("IsDoorLocked", IsDoorLocked);
00082     factory.registerSimpleAction("UnlockDoor", UnlockDoor);
00083 }


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 03:50:10