example.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <behavior_tree.h>
3 
5 {
6  public:
7  MyCondition(const std::string& name);
8  ~MyCondition();
9  BT::ReturnStatus Tick();
10 };
11 
13 {
14 }
15 
16 BT::ReturnStatus MyCondition::Tick()
17 {
18  std::cout << "The Condition is true" << std::endl;
19 
20  return NodeStatus::SUCCESS;
21 }
22 
23 class MyAction : public BT::ActionNode
24 {
25  public:
26  MyAction(const std::string& name);
27  ~MyAction();
28  BT::ReturnStatus Tick();
29  void Halt();
30 };
31 
32 MyAction::MyAction(const std::string& name) : ActionNode::ActionNode(name)
33 {
34 }
35 
36 BT::ReturnStatus MyAction::Tick()
37 {
38  std::cout << "The Action is doing some operations" << std::endl;
39  std::this_thread::sleep_for(std::chrono::milliseconds(500));
40  if (is_halted())
41  {
42  return NodeStatus::IDLE;
43  }
44 
45  std::cout << "The Action is doing some others operations" << std::endl;
46  std::this_thread::sleep_for(std::chrono::milliseconds(500));
47  if (is_halted())
48  {
49  return NodeStatus::IDLE;
50  }
51 
52  std::cout << "The Action is doing more operations" << std::endl;
53  std::this_thread::sleep_for(std::chrono::milliseconds(500));
54  if (is_halted())
55  {
56  return NodeStatus::IDLE;
57  }
58 
59  std::cout << "The Action has succeeded" << std::endl;
60  return NodeStatus::SUCCESS;
61 }
62 
64 {
65 }
66 
67 int main(int argc, char* argv[])
68 {
69  BT::SequenceNode* seq = new BT::SequenceNode("Sequence");
70  MyCondition* my_con_1 = new MyCondition("Condition");
71  MyAction* my_act_1 = new MyAction("Action");
72  int tick_time_milliseconds = 1000;
73 
74  seq->AddChild(my_con_1);
75  seq->AddChild(my_act_1);
76 
77  Execute(seq, tick_time_milliseconds);
78 
79  return 0;
80 }
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
MyAction(const std::string &name)
Definition: example.cpp:32
BT::ReturnStatus Tick()
Definition: example.cpp:16
ConditionNode(const std::string &name, const NodeConfiguration &config)
MyCondition(const std::string &name)
Definition: example.cpp:12
void Halt()
Definition: example.cpp:63
int main(int argc, char *argv[])
Definition: example.cpp:67
BT::ReturnStatus Tick()
Definition: example.cpp:36
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING...
Definition: sequence_node.h:34


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04