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 }
BT
Definition: ex01_wrap_legacy.cpp:29
FastAction::FastAction
FastAction(const std::string &name, const BT::NodeConfiguration &config)
Definition: gtest_wakeup.cpp:10
BT::BehaviorTreeFactory::registerNodeType
void registerNodeType(const std::string &ID)
Definition: bt_factory.h:364
FastAction
Definition: gtest_wakeup.cpp:6
BT::AsyncActionNode
The AsyncActionNode uses a different thread, where the action will be executed.
Definition: action_node.h:114
BT::Tree
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:125
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:342
bt_factory.h
FastAction::tick
BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: gtest_wakeup.cpp:19
BT::NodeConfiguration
Definition: tree_node.h:44
FastAction::providedPorts
static BT::PortsList providedPorts()
Definition: gtest_wakeup.cpp:14
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:278
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:251
BT::NodeStatus::SUCCESS
@ SUCCESS
xml_text
static const char * xml_text
Definition: ex01_wrap_legacy.cpp:52
TEST
TEST(WakeUp, BasicTest)
Definition: gtest_wakeup.cpp:26
BT::NodeStatus
NodeStatus
Definition: basic_types.h:35


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19