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 
00010 BT::NodeStatus CheckBattery();
00011 
00012 class GripperInterface
00013 {
00014   public:
00015     GripperInterface() : _opened(true)
00016     {
00017     }
00018 
00019     BT::NodeStatus open();
00020 
00021     BT::NodeStatus close();
00022 
00023   private:
00024     bool _opened;
00025 };
00026 
00027 //--------------------------------------
00028 
00029 // Example of custom SyncActionNode (synchronous action)
00030 // without ports.
00031 class ApproachObject : public BT::SyncActionNode
00032 {
00033   public:
00034     ApproachObject(const std::string& name) :
00035         BT::SyncActionNode(name, {})
00036     {
00037     }
00038 
00039     // You must override the virtual function tick()
00040     BT::NodeStatus tick() override;
00041 };
00042 
00043 // Example of custom SyncActionNode (synchronous action)
00044 // with an input port.
00045 class SaySomething : public BT::SyncActionNode
00046 {
00047   public:
00048     SaySomething(const std::string& name, const BT::NodeConfiguration& config)
00049       : BT::SyncActionNode(name, config)
00050     {
00051     }
00052 
00053     // You must override the virtual function tick()
00054     BT::NodeStatus tick() override;
00055 
00056     // It is mandatory to define this static method.
00057     static BT::PortsList providedPorts()
00058     {
00059         return{ BT::InputPort<std::string>("message") };
00060     }
00061 };
00062 
00063 //Same as class SaySomething, but to be registered with SimpleActionNode
00064 BT::NodeStatus SaySomethingSimple(BT::TreeNode& self);
00065 
00066 
00067 inline void RegisterNodes(BT::BehaviorTreeFactory& factory)
00068 {
00069     static GripperInterface grip_singleton;
00070 
00071     factory.registerSimpleCondition("CheckBattery", std::bind(CheckBattery));
00072     factory.registerSimpleAction("OpenGripper", std::bind(&GripperInterface::open, &grip_singleton));
00073     factory.registerSimpleAction("CloseGripper", std::bind(&GripperInterface::close, &grip_singleton));
00074     factory.registerNodeType<ApproachObject>("ApproachObject");
00075     factory.registerNodeType<SaySomething>("SaySomething");
00076 }
00077 
00078 } // end namespace
00079 
00080 #endif   // SIMPLE_BT_NODES_H


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15