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  NodeStatus tick() override
20  {
21  time_ = 5;
22  stop_loop_ = false;
23  int i = 0;
24  while (!stop_loop_ && i++ < time_)
25  {
26  std::this_thread::sleep_for(std::chrono::milliseconds(100));
27  }
28  return NodeStatus::SUCCESS;
29  }
30 
31  virtual void halt() override
32  {
33  stop_loop_ = true;
34  setStatus(NodeStatus::IDLE);
35  }
36 
37 private:
38  int time_;
39  std::atomic_bool stop_loop_;
40 };
41 
42 int main()
43 {
44  BT::SequenceNode root("root");
45  BT::SimpleActionNode action1("say_hello", std::bind(SayHello));
46  ActionTestNode action2("async_action");
47 
48  root.addChild(&action1);
49  root.addChild(&action2);
50 
51  int count = 0;
52 
54 
55  while (status == NodeStatus::RUNNING)
56  {
57  status = root.executeTick();
58 
59  std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / "
60  << action2.status() << std::endl;
61 
62  std::this_thread::sleep_for(std::chrono::milliseconds(100));
63  }
64 
65  return 0;
66 }
67 // Output
68 /*
69 
70 hello
71 0 : RUNNING / SUCCESS / RUNNING
72 hello
73 1 : RUNNING / SUCCESS / RUNNING
74 hello
75 2 : RUNNING / SUCCESS / RUNNING
76 hello
77 3 : RUNNING / SUCCESS / RUNNING
78 hello
79 4 : RUNNING / SUCCESS / RUNNING
80 hello
81 5 : SUCCESS / IDLE / IDLE
82 
83 */
std::atomic_bool stop_loop_
virtual void halt() override
NodeStatus status() const
Definition: tree_node.cpp:84
NodeStatus tick() override
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:78
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
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:32
int main()
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING...
Definition: sequence_node.h:33


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Mon Jul 3 2023 02:50:14