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 Davide Faconti - 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) : ActionNode(name)
18 {
19  boolean_value_ = true;
20  time_ = 3;
21  stop_loop_ = false;
22  tick_count_ = 0;
23 }
24 
26 {
27  halt();
28 }
29 
31 {
32  tick_count_++;
33  stop_loop_ = false;
34  int i = 0;
35  while (!stop_loop_ && i++ < time_)
36  {
37  std::this_thread::sleep_for(std::chrono::milliseconds(100));
38  }
39 
40  if (!stop_loop_)
41  {
43  }
44  else
45  {
46  return NodeStatus::IDLE;
47  }
48 }
49 
51 {
52  stop_loop_ = true;
54 }
55 
57 {
58  time_ = time;
59 }
60 
61 void BT::AsyncActionTest::setBoolean(bool boolean_value)
62 {
63  boolean_value_ = boolean_value;
64 }
65 
66 //----------------------------------------------
67 
69 {
70  tick_count_ = 0;
71  boolean_value_ = true;
72 }
73 
75 {
76  tick_count_++;
78 }
79 
80 void BT::SyncActionTest::setBoolean(bool boolean_value)
81 {
82  boolean_value_ = boolean_value;
83 }
SyncActionTest(const std::string &name)
const std::string & name() const
Definition: tree_node.cpp:92
AsyncActionTest(const std::string &name)
The AsyncActionNode a different thread where the action will be executed.
Definition: action_node.h:110
void setBoolean(bool boolean_value)
virtual void halt() override
The method used to interrupt the execution of a RUNNING node.
The SyncActionNode is an helper derived class that explicitly forbids the status RUNNING and doesn&#39;t ...
Definition: action_node.h:50
BT::NodeStatus tick() override
Method to be implemented by the user.
std::atomic_bool stop_loop_
void setTime(int time)
void setBoolean(bool boolean_value)
NodeStatus
Definition: basic_types.h:28
BT::NodeStatus tick() override
Method to be implemented by the user.
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:43


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53