action_test_node.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
2  * Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
11 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 */
13 
14 #include "action_test_node.h"
15 #include <string>
16 
17 BT::AsyncActionTest::AsyncActionTest(const std::string& name, BT::Duration deadline_ms) :
19 {
21  time_ = deadline_ms;
22  tick_count_ = 0;
23 }
24 
26 {
27  using std::chrono::high_resolution_clock;
28  tick_count_++;
29 
30  auto initial_time = high_resolution_clock::now();
31 
32  // we simulate an asynchronous action that takes an amount of time equal to time_
33  while (!isHaltRequested() && high_resolution_clock::now() < initial_time + time_)
34  {
35  std::this_thread::sleep_for(std::chrono::milliseconds(1));
36  }
37 
38  // check if we exited the while() loop because of the flag stop_loop_
39  if (isHaltRequested())
40  {
41  return NodeStatus::IDLE;
42  }
43 
45  {
47  }
49  {
51  }
52 
53  return expected_result_;
54 }
55 
57 {
58  // do more cleanup here if necessary
60 }
61 
63 {
64  time_ = time;
65 }
66 
68 {
69  expected_result_ = res;
70 }
71 
72 //----------------------------------------------
73 
75 {
76  tick_count_ = 0;
78 }
79 
81 {
82  tick_count_++;
83  return expected_result_;
84 }
85 
87 {
88  expected_result_ = res;
89 }
SyncActionTest(const std::string &name)
virtual void halt() override
AsyncActionTest(const std::string &name, BT::Duration deadline_ms=std::chrono::milliseconds(100))
bool isHaltRequested() const
Definition: action_node.h:121
The AsyncActionNode uses a different thread, where the action will be executed.
Definition: action_node.h:114
virtual void halt() override
void setExpectedResult(NodeStatus res)
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn&#39;t require a...
Definition: action_node.h:52
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:101
std::atomic< int > tick_count_
void setTime(BT::Duration time)
BT::NodeStatus tick() override
Method to be implemented by the user.
NodeStatus expected_result_
NodeStatus
Definition: basic_types.h:35
std::atomic< NodeStatus > expected_result_
void setExpectedResult(NodeStatus res)
BT::NodeStatus tick() override
Method to be implemented by the user.
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:362


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