broken_sequence.cpp
Go to the documentation of this file.
1 #include "Blackboard/blackboard_local.h"
4 
5 using namespace BT;
6 
8 {
9  printf("hello\n");
10  return NodeStatus::SUCCESS;
11 }
12 
13 class ActionTestNode : public ActionNode
14 {
15  public:
16  ActionTestNode(const std::string& name) : ActionNode(name)
17  {
18  }
19 
20  NodeStatus tick() override
21  {
22  time_ = 5;
23  stop_loop_ = false;
24  int i = 0;
25  while (!stop_loop_ && i++ < time_)
26  {
27  std::this_thread::sleep_for(std::chrono::milliseconds(100));
28  }
29  return NodeStatus::SUCCESS;
30  }
31 
32  virtual void halt() override
33  {
34  stop_loop_ = true;
35  setStatus(NodeStatus::IDLE);
36  }
37 
38  private:
39  int time_;
40  std::atomic_bool stop_loop_;
41 };
42 
43 int main()
44 {
45  BT::SequenceNode root("root");
46  BT::SimpleActionNode action1("say_hello", std::bind(SayHello));
47  ActionTestNode action2("async_action");
48 
49  root.addChild(&action1);
50  root.addChild(&action2);
51 
52  int count = 0;
53 
55 
56  while (status == NodeStatus::RUNNING)
57  {
58  status = root.executeTick();
59 
60  std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / "
61  << action2.status() << std::endl;
62 
63  std::this_thread::sleep_for(std::chrono::milliseconds(100));
64  }
65 
66  haltAllActions(&root);
67 
68  return 0;
69 }
70 // Output
71 /*
72 
73 hello
74 0 : RUNNING / SUCCESS / RUNNING
75 hello
76 1 : RUNNING / SUCCESS / RUNNING
77 hello
78 2 : RUNNING / SUCCESS / RUNNING
79 hello
80 3 : RUNNING / SUCCESS / RUNNING
81 hello
82 4 : RUNNING / SUCCESS / RUNNING
83 hello
84 5 : SUCCESS / IDLE / IDLE
85 
86 */
virtual void halt() override
NodeStatus tick() override
void haltAllActions(TreeNode *root_node)
NodeStatus SayHello()
static volatile int count
Definition: minitrace.cpp:55
The SimpleActionNode provides an easy to use SyncActionNode. The user should simply provide a callbac...
Definition: action_node.h:81
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
NodeStatus status() const
Definition: tree_node.cpp:56
ActionTestNode(const std::string &name)
NodeStatus
Definition: basic_types.h:35
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:33
int main()
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