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::NodeConfig& config)
11  : ThreadedAction(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 BTCPP_format="4">
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.tickOnce();
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
Definition: gtest_wakeup.cpp:6
BT::Tree
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:91
bt_factory.h
FastAction::tick
BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: gtest_wakeup.cpp:19
FastAction::providedPorts
static BT::PortsList providedPorts()
Definition: gtest_wakeup.cpp:14
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::BehaviorTreeFactory::registerNodeType
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
Definition: bt_factory.h:326
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
createTreeFromText will parse the XML directly from string. The XML needs to contain either a single ...
Definition: bt_factory.cpp:395
FastAction::FastAction
FastAction(const std::string &name, const BT::NodeConfig &config)
Definition: gtest_wakeup.cpp:10
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:209
BT::NodeStatus::SUCCESS
@ SUCCESS
BT::ThreadedAction
The ThreadedAction executes the tick in a different thread.
Definition: action_node.h:116
BT::NodeConfig
Definition: tree_node.h:73
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:33


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16