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
The method used to interrupt the execution of a RUNNING node.
int main()
NodeStatus SayHello()
Definition: test_package.cpp:6
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)
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
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