00001 #include "behaviortree_cpp/blackboard/blackboard_local.h" 00002 #include "dummy_nodes.h" 00003 00004 using namespace BT; 00005 00014 int main() 00015 { 00016 using namespace DummyNodes; 00017 GripperInterface gripper; 00018 00019 // sequence_root will be the root of our tree 00020 BT::SequenceNode sequence_root("sequence"); 00021 00022 // Function pointers can be wrapped inside ActionNodeBase 00023 // using the SimpleActionNode 00024 SimpleActionNode say_hello("action_hello", std::bind(SayHello)); 00025 00026 // SimpleActionNode works also with class methods, using std::bind 00027 SimpleActionNode open_gripper("open_gripper", std::bind(&GripperInterface::open, &gripper)); 00028 SimpleActionNode close_gripper("close_gripper", std::bind(&GripperInterface::close, &gripper)); 00029 00030 // To be able to use ALL the functionalities of a TreeNode, 00031 // your should create a class that inherits from either: 00032 // - ConditionNode (synchronous execution) 00033 // - ActionNodeBase (synchronous execution) 00034 // - ActionNode (asynchronous execution in a separate thread). 00035 ApproachObject approach_object("approach_object"); 00036 00037 // Add children to the sequence. 00038 // they will be executed in the same order they are added. 00039 sequence_root.addChild(&say_hello); 00040 sequence_root.addChild(&open_gripper); 00041 sequence_root.addChild(&approach_object); 00042 sequence_root.addChild(&close_gripper); 00043 00044 // The tick is propagated to all the children. 00045 // until one of them returns FAILURE or RUNNING. 00046 // In this case all of them return SUCCESS immediately 00047 sequence_root.executeTick(); 00048 00049 // needed when you use ActionNodes with their own thread 00050 haltAllActions(&sequence_root); 00051 00052 return 0; 00053 }