dummy_nodes.h
Go to the documentation of this file.
00001 #ifndef SIMPLE_BT_NODES_H
00002 #define SIMPLE_BT_NODES_H
00003 
00004 #include "behaviortree_cpp/behavior_tree.h"
00005 #include "behaviortree_cpp/bt_factory.h"
00006 
00007 namespace DummyNodes
00008 {
00009 BT::NodeStatus SayHello();
00010 
00011 BT::NodeStatus CheckBattery();
00012 
00013 BT::NodeStatus CheckTemperature();
00014 
00015 class GripperInterface
00016 {
00017   public:
00018     GripperInterface() : _opened(true)
00019     {
00020     }
00021 
00022     BT::NodeStatus open();
00023 
00024     BT::NodeStatus close();
00025 
00026   private:
00027     bool _opened;
00028 };
00029 
00030 //--------------------------------------
00031 
00032 // Example of custom SyncActionNode (synchronous action)
00033 // without NodeParameters.
00034 class ApproachObject : public BT::SyncActionNode
00035 {
00036   public:
00037     ApproachObject(const std::string& name) : BT::SyncActionNode(name)
00038     {
00039     }
00040 
00041     // You must override the virtual function tick()
00042     BT::NodeStatus tick() override;
00043 };
00044 
00045 // Example of custom SyncActionNode (synchronous action)
00046 // with NodeParameters.
00047 class SaySomething : public BT::SyncActionNode
00048 {
00049   public:
00050     SaySomething(const std::string& name, const BT::NodeParameters& params)
00051       : BT::SyncActionNode(name, params)
00052     {
00053     }
00054 
00055     // You must override the virtual function tick()
00056     BT::NodeStatus tick() override;
00057 
00058     // It is mandatory to define this static method.
00059     // If you don't, BehaviorTreeFactory::registerNodeType will not compile.
00060     static const BT::NodeParameters& requiredNodeParameters()
00061     {
00062         static BT::NodeParameters params = {{"message", ""}};
00063         return params;
00064     }
00065 };
00066 
00067 inline void RegisterNodes(BT::BehaviorTreeFactory& factory)
00068 {
00069     static GripperInterface gi;
00070     factory.registerSimpleAction("SayHello", std::bind(SayHello));
00071     factory.registerSimpleCondition("CheckBattery", std::bind(CheckBattery));
00072     factory.registerSimpleCondition("CheckTemperature", std::bind(CheckTemperature));
00073     factory.registerSimpleAction("OpenGripper", std::bind(&GripperInterface::open, &gi));
00074     factory.registerSimpleAction("CloseGripper", std::bind(&GripperInterface::close, &gi));
00075     factory.registerNodeType<ApproachObject>("ApproachObject");
00076     factory.registerNodeType<SaySomething>("SaySomething");
00077 }
00078 }
00079 
00080 #endif   // SIMPLE_BT_NODES_H


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