Go to the documentation of this file.00001 #include <iostream>
00002 #include <behavior_tree.h>
00003
00004 class MyCondition : public BT::ConditionNode
00005 {
00006 public:
00007 MyCondition(const std::string& name);
00008 ~MyCondition();
00009 BT::ReturnStatus Tick();
00010 };
00011
00012 MyCondition::MyCondition(const std::string& name) : BT::ConditionNode::ConditionNode(name)
00013 {
00014 }
00015
00016 BT::ReturnStatus MyCondition::Tick()
00017 {
00018 std::cout << "The Condition is true" << std::endl;
00019
00020 return NodeStatus::SUCCESS;
00021 }
00022
00023 class MyAction : public BT::ActionNode
00024 {
00025 public:
00026 MyAction(const std::string& name);
00027 ~MyAction();
00028 BT::ReturnStatus Tick();
00029 void Halt();
00030 };
00031
00032 MyAction::MyAction(const std::string& name) : ActionNode::ActionNode(name)
00033 {
00034 }
00035
00036 BT::ReturnStatus MyAction::Tick()
00037 {
00038 std::cout << "The Action is doing some operations" << std::endl;
00039 std::this_thread::sleep_for(std::chrono::milliseconds(500));
00040 if (is_halted())
00041 {
00042 return NodeStatus::IDLE;
00043 }
00044
00045 std::cout << "The Action is doing some others operations" << std::endl;
00046 std::this_thread::sleep_for(std::chrono::milliseconds(500));
00047 if (is_halted())
00048 {
00049 return NodeStatus::IDLE;
00050 }
00051
00052 std::cout << "The Action is doing more operations" << std::endl;
00053 std::this_thread::sleep_for(std::chrono::milliseconds(500));
00054 if (is_halted())
00055 {
00056 return NodeStatus::IDLE;
00057 }
00058
00059 std::cout << "The Action has succeeded" << std::endl;
00060 return NodeStatus::SUCCESS;
00061 }
00062
00063 void MyAction::Halt()
00064 {
00065 }
00066
00067 int main(int argc, char* argv[])
00068 {
00069 BT::SequenceNode* seq = new BT::SequenceNode("Sequence");
00070 MyCondition* my_con_1 = new MyCondition("Condition");
00071 MyAction* my_act_1 = new MyAction("Action");
00072 int tick_time_milliseconds = 1000;
00073
00074 seq->AddChild(my_con_1);
00075 seq->AddChild(my_act_1);
00076
00077 Execute(seq, tick_time_milliseconds);
00078
00079 return 0;
00080 }