3 #include <gtest/gtest.h>
10 <root BTCPP_format="4" main_tree_to_execute="BehaviorTree">
11 <BehaviorTree ID="BehaviorTree">
12 <Fallback name="root">
14 <ReactiveSequence name="navigation_subtree">
16 <Condition ID="IsStuck"/>
18 <SequenceWithMemory name="navigate">
19 <Action ID="ComputePathToPose"/>
20 <Action ID="FollowPath"/>
24 <SequenceWithMemory 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();
48 TestNode(
const std::string&
name) : _expected_result(true), _tick_count(0), _name(
name)
53 _expected_result = will_succeed;
70 std::cout << _name <<
": " << (_expected_result ?
"true" :
"false") << std::endl;
72 return expectedResult();
132 std::cout <<
"FollowPath::started" << std::endl;
133 _initial_time =
Now();
149 std::cout <<
"FollowPath::halt" << std::endl;
164 template <
typename Original,
typename Casted>
167 if(
dynamic_cast<Casted*
>(ptr))
169 destination =
dynamic_cast<Casted*
>(ptr);
175 TEST(Navigationtest, MoveBaseRecovery)
188 IsStuck* first_stuck_node =
nullptr;
189 IsStuck* second_stuck_node =
nullptr;
194 for(
auto& subtree : tree.subtrees)
196 for(
auto& node : subtree->nodes)
198 auto ptr = node.get();
200 if(!first_stuck_node)
214 ASSERT_TRUE(first_stuck_node);
215 ASSERT_TRUE(second_stuck_node);
216 ASSERT_TRUE(back_spin_node);
217 ASSERT_TRUE(compute_node);
218 ASSERT_TRUE(follow_node);
220 std::cout <<
"-----------------------" << std::endl;
225 first_stuck_node->setExpectedResult(
false);
229 status = tree.tickWhileRunning();
236 ASSERT_GE(first_stuck_node->tickCount(), 6);
238 ASSERT_EQ(second_stuck_node->tickCount(), 0);
239 ASSERT_EQ(back_spin_node->tickCount(), 0);
241 ASSERT_EQ(compute_node->tickCount(), 1);
242 ASSERT_EQ(follow_node->tickCount(), 1);
245 std::cout <<
"-----------------------" << std::endl;
250 first_stuck_node->resetTickCount();
251 second_stuck_node->resetTickCount();
252 compute_node->resetTickCount();
253 follow_node->resetTickCount();
254 back_spin_node->resetTickCount();
263 first_stuck_node->setExpectedResult(
true);
264 second_stuck_node->setExpectedResult(
true);
266 status = tree.tickWhileRunning();
274 ASSERT_GE(first_stuck_node->tickCount(), 2);
276 ASSERT_EQ(second_stuck_node->tickCount(), 1);
277 ASSERT_EQ(back_spin_node->tickCount(), 1);
280 ASSERT_EQ(compute_node->tickCount(), 1);
282 ASSERT_EQ(follow_node->tickCount(), 0);
289 std::cout <<
"-----------------------" << std::endl;
294 first_stuck_node->resetTickCount();
295 second_stuck_node->resetTickCount();
296 compute_node->resetTickCount();
297 follow_node->resetTickCount();
298 back_spin_node->resetTickCount();
300 first_stuck_node->setExpectedResult(
false);
301 second_stuck_node->setExpectedResult(
false);
305 status = tree.tickWhileRunning();
312 ASSERT_GE(first_stuck_node->tickCount(), 6);
313 ASSERT_EQ(second_stuck_node->tickCount(), 0);
314 ASSERT_EQ(back_spin_node->tickCount(), 0);