3 #include <gtest/gtest.h> 10 <root main_tree_to_execute="BehaviorTree"> 11 <BehaviorTree ID="BehaviorTree"> 12 <FallbackStar name="root"> 13 <Sequence name="navigation_subtree"> 15 <Condition ID="IsStuck"/> 17 <SequenceStar name="navigate"> 18 <Action ID="ComputePathToPose"/> 19 <Action ID="FollowPath"/> 22 <SequenceStar name="stuck_recovery"> 23 <Condition ID="IsStuck"/> 24 <Action ID="BackUpAndSpin"/> 35 inline std::chrono::high_resolution_clock::time_point
Now()
37 return std::chrono::high_resolution_clock::now();
48 _expected_result(true),
55 _expected_result = will_succeed;
66 std::cout << _name <<
": "<< (_expected_result?
"true" :
"false") << std::endl;
68 return expectedResult();
118 std::cout <<
"FollowPath::started" << std::endl;
119 auto initial_time =
Now();
124 setStatusRunningAndYield();
130 std::cout <<
"FollowPath::halt" << std::endl;
143 template <
typename Original,
typename Casted>
146 if( dynamic_cast<Casted*>(ptr) )
148 destination =
dynamic_cast<Casted*
>(ptr);
154 TEST(Navigationtest, MoveBaseRecovery)
167 IsStuck *first_stuck_node =
nullptr;
168 IsStuck *second_stuck_node =
nullptr;
173 for (
auto& node: tree.nodes)
175 auto ptr = node.get();
177 if( !first_stuck_node )
189 ASSERT_TRUE( first_stuck_node );
190 ASSERT_TRUE( second_stuck_node );
191 ASSERT_TRUE( back_spin_node );
192 ASSERT_TRUE( compute_node );
193 ASSERT_TRUE( follow_node );
195 std::cout <<
"-----------------------" << std::endl;
211 ASSERT_GE( first_stuck_node->
tickCount(), 6);
213 ASSERT_EQ( second_stuck_node->
tickCount(), 0 );
214 ASSERT_EQ( back_spin_node->
tickCount(), 0 );
216 ASSERT_EQ( compute_node->
tickCount(), 1 );
217 ASSERT_EQ( follow_node->
tickCount(), 1 );
218 ASSERT_FALSE( follow_node->
wasHalted() );
220 std::cout <<
"-----------------------" << std::endl;
249 ASSERT_GE( first_stuck_node->
tickCount(), 2);
251 ASSERT_EQ( second_stuck_node->
tickCount(), 1 );
252 ASSERT_EQ( back_spin_node->
tickCount(), 1 );
255 ASSERT_EQ( compute_node->
tickCount(), 1 );
257 ASSERT_EQ( follow_node->
tickCount(), 0 );
265 std::cout <<
"-----------------------" << std::endl;
288 ASSERT_GE( first_stuck_node->
tickCount(), 6);
289 ASSERT_EQ( second_stuck_node->
tickCount(), 0 );
290 ASSERT_EQ( back_spin_node->
tickCount(), 0 );
295 ASSERT_FALSE( follow_node->
wasHalted() );
NodeStatus tick() override
Method to be implemented by the user.
BackUpAndSpin(const std::string &name)
void registerNodeType(const std::string &ID)
const std::string xml_text
virtual NodeStatus executeTick() overridefinal
The method that will be executed to invoke tick(); and setStatus();.
ComputePathToPose(const std::string &name)
void TryDynamicCastPtr(Original *ptr, Casted *&destination)
NodeStatus tick() override
Method to be implemented by the user.
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 setExpectedResult(bool will_succeed)
FollowPath(const std::string &name)
The SyncActionNode is an helper derived class that explicitly forbids the status RUNNING and doesn't ...
std::chrono::high_resolution_clock::time_point Now()
void halt() override
The method used to interrupt the execution of a RUNNING node.
TEST(Navigationtest, MoveBaseRecovery)
NodeStatus tick() override
Method to be implemented by the user.
NodeStatus status() const
TestNode(const std::string &name)
std::chrono::milliseconds Milliseconds
NodeStatus expectedResult() const
IsStuck(const std::string &name)
Tree buildTreeFromText(const BehaviorTreeFactory &factory, const std::string &text, const Blackboard::Ptr &blackboard=Blackboard::Ptr())