gtest_wakeup.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
3 
4 using namespace BT;
5 
7 {
8 public:
9  // Any TreeNode with ports must have a constructor with this signature
10  FastAction(const std::string& name, const BT::NodeConfiguration& config) :
11  AsyncActionNode(name, config)
12  {}
13 
15  {
16  return {};
17  }
18 
19  BT::NodeStatus tick() override
20  {
21  std::this_thread::sleep_for(std::chrono::milliseconds(10));
23  }
24 };
25 
26 TEST(WakeUp, BasicTest)
27 {
28  static const char* xml_text = R"(
29 
30 <root>
31  <BehaviorTree ID="MainTree">
32  <FastAction/>
33  </BehaviorTree>
34 </root> )";
35 
36  BehaviorTreeFactory factory;
37  factory.registerNodeType<FastAction>("FastAction");
38 
39  Tree tree = factory.createTreeFromText(xml_text);
40 
41  using namespace std::chrono;
42 
43  auto t1 = system_clock::now();
44  tree.tickRoot();
45  tree.sleep(milliseconds(200));
46  auto t2 = system_clock::now();
47 
48  auto dT = duration_cast<milliseconds>(t2 - t1).count();
49  std::cout << "Woke up after msec: " << dT << std::endl;
50 
51  ASSERT_LT(dT, 25);
52 }
void registerNodeType(const std::string &ID)
Definition: bt_factory.h:364
The AsyncActionNode uses a different thread, where the action will be executed.
Definition: action_node.h:114
static const char * xml_text
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:251
static BT::PortsList providedPorts()
TEST(WakeUp, BasicTest)
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:278
BT::NodeStatus tick() override
Method to be implemented by the user.
FastAction(const std::string &name, const BT::NodeConfiguration &config)
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:125
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:333
static volatile int count
Definition: minitrace.cpp:55
NodeStatus
Definition: basic_types.h:35


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