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) :
18  AsyncActionNode(name, {})
19 {
20  boolean_value_ = true;
21  time_ = deadline_ms;
22  stop_loop_ = false;
23  tick_count_ = 0;
24 }
25 
27 {
28  halt();
29 }
30 
32 {
33  using std::chrono::high_resolution_clock;
34  tick_count_++;
35  stop_loop_ = false;
36  auto initial_time = high_resolution_clock::now();
37 
38  while (!stop_loop_ && high_resolution_clock::now() < initial_time + time_)
39  {
40  std::this_thread::sleep_for(std::chrono::milliseconds(1));
41  }
42 
43  if (!stop_loop_)
44  {
46  }
47  else
48  {
49  return NodeStatus::IDLE;
50  }
51 }
52 
54 {
55  stop_loop_ = true;
56 }
57 
59 {
60  time_ = time;
61 }
62 
63 void BT::AsyncActionTest::setBoolean(bool boolean_value)
64 {
65  boolean_value_ = boolean_value;
66 }
67 
68 //----------------------------------------------
69 
71  SyncActionNode(name, {})
72 {
73  tick_count_ = 0;
74  boolean_value_ = true;
75 }
76 
78 {
79  tick_count_++;
81 }
82 
83 void BT::SyncActionTest::setBoolean(bool boolean_value)
84 {
85  boolean_value_ = boolean_value;
86 }
std::atomic_bool boolean_value_
SyncActionTest(const std::string &name)
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
AsyncActionTest(const std::string &name, BT::Duration deadline_ms)
The AsyncActionNode uses a different thread where the action will be executed.
Definition: action_node.h:105
void setBoolean(bool boolean_value)
virtual void halt() override
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn&#39;t require a...
Definition: action_node.h:52
std::atomic< int > tick_count_
void setTime(BT::Duration time)
BT::NodeStatus tick() override
Method to be implemented by the user.
std::atomic_bool stop_loop_
void setBoolean(bool boolean_value)
NodeStatus
Definition: basic_types.h:35
BT::NodeStatus tick() override
Method to be implemented by the user.
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:339


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04