test_package.cpp
Go to the documentation of this file.
3 
4 using namespace BT;
5 
7 {
8  printf("hello\n");
9  return NodeStatus::SUCCESS;
10 }
11 
12 class ActionTestNode : public ActionNode
13 {
14  public:
15  ActionTestNode(const std::string& name) : ActionNode(name)
16  {
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  haltAllActions(&root);
66 
67  return 0;
68 }
std::atomic_bool stop_loop_
virtual void halt() override
int main()
NodeStatus SayHello()
Definition: test_package.cpp:6
NodeStatus tick() override
void haltAllActions(TreeNode *root_node)
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
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:05