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();
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& node : tree.nodes)
196 auto ptr = node.get();
198 if (!first_stuck_node)
211 ASSERT_TRUE(first_stuck_node);
212 ASSERT_TRUE(second_stuck_node);
213 ASSERT_TRUE(back_spin_node);
214 ASSERT_TRUE(compute_node);
215 ASSERT_TRUE(follow_node);
217 std::cout <<
"-----------------------" << std::endl;
226 status = tree.tickRoot();
233 ASSERT_GE(first_stuck_node->
tickCount(), 6);
235 ASSERT_EQ(second_stuck_node->
tickCount(), 0);
236 ASSERT_EQ(back_spin_node->
tickCount(), 0);
242 std::cout <<
"-----------------------" << std::endl;
263 status = tree.tickRoot();
271 ASSERT_GE(first_stuck_node->
tickCount(), 2);
273 ASSERT_EQ(second_stuck_node->
tickCount(), 1);
274 ASSERT_EQ(back_spin_node->
tickCount(), 1);
286 std::cout <<
"-----------------------" << std::endl;
302 status = tree.tickRoot();
309 ASSERT_GE(first_stuck_node->
tickCount(), 6);
310 ASSERT_EQ(second_stuck_node->
tickCount(), 0);
311 ASSERT_EQ(back_spin_node->
tickCount(), 0);