4 #include <gtest/gtest.h> 9 using Timepoint = std::chrono::time_point<std::chrono::steady_clock>;
15 const std::string &node_name,
17 :
BT::CoroActionNode(node_name, config)
18 , will_fail_(will_fail)
24 virtual void halt()
override 26 std::cout <<
"Action was halted. doing cleanup here" << std::endl;
27 start_time_ = Timepoint::min();
45 std::cout <<
"Starting action " << std::endl;
48 if (start_time_ == Timepoint::min())
50 start_time_ = std::chrono::steady_clock::now();
53 while (std::chrono::steady_clock::now() < (start_time_ + timeout_))
55 setStatusRunningAndYield();
60 std::cout <<
"Done" << std::endl;
61 start_time_ = Timepoint::min();
90 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
94 EXPECT_FALSE( node.wasHalted() );
97 EXPECT_FALSE( node.wasHalted() );
99 node.will_fail_ =
true;
101 <<
"Should execute again and retun failure";
102 EXPECT_FALSE( node.wasHalted() );
106 <<
"Shoudln't fail because we set status to idle";
107 EXPECT_FALSE( node.wasHalted() );
111 TEST(CoroTest, do_action_timeout)
115 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
123 EXPECT_TRUE( node.wasHalted() );
128 EXPECT_FALSE( node.wasHalted() );
135 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
137 SimpleCoroAction actionA( milliseconds(200),
false,
"action_A", node_config_);
138 SimpleCoroAction actionB( milliseconds(200),
false,
"action_B", node_config_);
147 EXPECT_FALSE( actionA.wasHalted() );
virtual void halt() override
TEST(CoroTest, do_action)
std::chrono::time_point< std::chrono::steady_clock > Timepoint
static Blackboard::Ptr create(Blackboard::Ptr parent={})
BT::NodeStatus executeWhileRunning(BT::TreeNode &node)
The TimeoutNode will halt() a running child if the latter has been RUNNING for more than a give time...
std::chrono::milliseconds Millisecond
Blackboard::Ptr blackboard
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
The CoroActionNode class is an ideal candidate for asynchronous actions which need to communicate wit...
void setChild(TreeNode *child)
Abstract base class for Behavior Tree Nodes.
SimpleCoroAction(milliseconds timeout, bool will_fail, const std::string &node_name, const BT::NodeConfiguration &config)
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
void setRequiredTime(Millisecond ms)
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING...
std::chrono::milliseconds timeout_