3 #include <gtest/gtest.h> 10 <root main_tree_to_execute="BehaviorTree"> 11 <BehaviorTree ID="BehaviorTree"> 12 <Fallback name="root"> 14 <ReactiveSequence name="navigation_subtree"> 16 <Condition ID="IsStuck"/> 18 <SequenceStar name="navigate"> 19 <Action ID="ComputePathToPose"/> 20 <Action ID="FollowPath"/> 24 <SequenceStar name="stuck_recovery"> 25 <Condition ID="IsStuck"/> 26 <Action ID="BackUpAndSpin"/> 38 inline std::chrono::high_resolution_clock::time_point
Now()
40 return std::chrono::high_resolution_clock::now();
51 _expected_result(true),
58 _expected_result = will_succeed;
69 std::cout << _name <<
": "<< (_expected_result?
"true" :
"false") << std::endl;
71 return expectedResult();
121 std::cout <<
"FollowPath::started" << std::endl;
122 auto initial_time =
Now();
127 setStatusRunningAndYield();
132 std::cout <<
"FollowPath::halt" << std::endl;
145 template <
typename Original,
typename Casted>
148 if( dynamic_cast<Casted*>(ptr) )
150 destination =
dynamic_cast<Casted*
>(ptr);
156 TEST(Navigationtest, MoveBaseRecovery)
169 IsStuck *first_stuck_node =
nullptr;
170 IsStuck *second_stuck_node =
nullptr;
175 for (
auto& node: tree.nodes)
177 auto ptr = node.get();
179 if( !first_stuck_node )
191 ASSERT_TRUE( first_stuck_node );
192 ASSERT_TRUE( second_stuck_node );
193 ASSERT_TRUE( back_spin_node );
194 ASSERT_TRUE( compute_node );
195 ASSERT_TRUE( follow_node );
197 std::cout <<
"-----------------------" << std::endl;
213 ASSERT_GE( first_stuck_node->
tickCount(), 6);
215 ASSERT_EQ( second_stuck_node->
tickCount(), 0 );
216 ASSERT_EQ( back_spin_node->
tickCount(), 0 );
218 ASSERT_EQ( compute_node->
tickCount(), 1 );
219 ASSERT_EQ( follow_node->
tickCount(), 1 );
220 ASSERT_FALSE( follow_node->
wasHalted() );
222 std::cout <<
"-----------------------" << std::endl;
251 ASSERT_GE( first_stuck_node->
tickCount(), 2);
253 ASSERT_EQ( second_stuck_node->
tickCount(), 1 );
254 ASSERT_EQ( back_spin_node->
tickCount(), 1 );
257 ASSERT_EQ( compute_node->
tickCount(), 1 );
259 ASSERT_EQ( follow_node->
tickCount(), 0 );
267 std::cout <<
"-----------------------" << std::endl;
290 ASSERT_GE( first_stuck_node->
tickCount(), 6);
291 ASSERT_EQ( second_stuck_node->
tickCount(), 0 );
292 ASSERT_EQ( back_spin_node->
tickCount(), 0 );
297 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)
virtual NodeStatus executeTick() overridefinal
The method that should be used 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 ActionNode that explicitly prevents the status RUNNING and doesn't require a...
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
std::chrono::high_resolution_clock::time_point Now()
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
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
static const char * xml_text
NodeStatus expectedResult() const
IsStuck(const std::string &name)