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
The method used to interrupt the execution of a RUNNING node.
The AsyncActionNode a different thread where the action will be executed.
Definition: action_node.h:110
NodeStatus tick() override
Method to be implemented by the user.
void haltAllActions(TreeNode *root_node)
NodeStatus SayHello()
static volatile int count
Definition: minitrace.cpp:55
The SimpleActionNode provides an easy to use ActionNode. The user should simply provide a callback wi...
Definition: action_node.h:77
void addChild(TreeNode *child)
NodeStatus status() const
Definition: tree_node.cpp:75
ActionTestNode(const std::string &name)
NodeStatus
Definition: basic_types.h:28
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
int main()
The SequenceNode is used to execute a sequence of children. If any child returns RUNNING, previous children will be ticked again.
Definition: sequence_node.h:34


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53