Skip to content

Commit d078e1e

Browse files
authored
planner_cspace: fix flaky navigation tests (#768)
- tweak trajectory_tracker parameter - use default switch back wait duration - fix parameterized rostest result - wait topics on init - fix local map publish timing on stuck tests
1 parent b53933f commit d078e1e

File tree

4 files changed

+90
-47
lines changed

4 files changed

+90
-47
lines changed

planner_cspace/test/src/test_navigate.cpp

+86-42
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,53 @@ class Navigate : public ::testing::Test
9696

9797
virtual void SetUp()
9898
{
99-
test_scope_ = "[" + std::to_string(getpid()) + "] ";
99+
test_scope_ =
100+
"[" + std::to_string(getpid()) + "/" +
101+
::testing::UnitTest::GetInstance()->current_test_info()->name() + "] ";
100102

101-
srv_forget_.waitForExistence(ros::Duration(10.0));
102103
ros::Rate rate(10.0);
103104

105+
const ros::Time deadline = ros::Time::now() + ros::Duration(15.0);
106+
while (ros::ok())
107+
{
108+
rate.sleep();
109+
ASSERT_LT(ros::Time::now(), deadline)
110+
<< test_scope_ << "Initialization timeout: "
111+
<< "sub_map:" << sub_map_.getNumPublishers() << " "
112+
<< "sub_map_local:" << sub_map_local_.getNumPublishers() << " "
113+
<< "sub_costmap:" << sub_costmap_.getNumPublishers() << " "
114+
<< "sub_status:" << sub_status_.getNumPublishers() << " "
115+
<< "pub_map:" << pub_map_.getNumSubscribers() << " "
116+
<< "pub_map_local:" << pub_map_local_.getNumSubscribers() << " "
117+
<< "pub_initial_pose:" << pub_initial_pose_.getNumSubscribers() << " "
118+
<< "pub_patrol_nodes:" << pub_patrol_nodes_.getNumSubscribers() << " ";
119+
if (sub_map_.getNumPublishers() > 0 &&
120+
sub_map_local_.getNumPublishers() > 0 &&
121+
sub_costmap_.getNumPublishers() > 0 &&
122+
sub_status_.getNumPublishers() > 0 &&
123+
pub_map_.getNumSubscribers() > 0 &&
124+
pub_map_local_.getNumSubscribers() > 0 &&
125+
pub_initial_pose_.getNumSubscribers() > 0 &&
126+
pub_patrol_nodes_.getNumSubscribers() > 0)
127+
{
128+
break;
129+
}
130+
}
131+
ASSERT_TRUE(srv_forget_.waitForExistence(ros::Duration(10.0)));
132+
104133
geometry_msgs::PoseWithCovarianceStamped pose;
105134
pose.header.frame_id = "map";
106135
pose.pose.pose.position.x = 2.5;
107136
pose.pose.pose.position.y = 0.45;
108137
pose.pose.pose.orientation.z = 1.0;
109138
pub_initial_pose_.publish(pose);
110139

111-
const ros::Time deadline = ros::Time::now() + ros::Duration(15);
112-
113140
while (ros::ok())
114141
{
115142
ros::spinOnce();
116143
rate.sleep();
117144
const ros::Time now = ros::Time::now();
118-
if (now > deadline)
119-
{
120-
FAIL() << test_scope_ << now << " SetUp: transform timeout" << std::endl;
121-
}
145+
ASSERT_LT(now, deadline) << test_scope_ << "Initial transform timeout";
122146
if (tfbuf_.canTransform("map", "base_link", now, ros::Duration(0.5)))
123147
{
124148
break;
@@ -129,24 +153,23 @@ class Navigate : public ::testing::Test
129153
{
130154
ros::spinOnce();
131155
rate.sleep();
132-
const ros::Time now = ros::Time::now();
133-
if (now > deadline)
134-
{
135-
FAIL() << test_scope_ << now << " SetUp: map timeout" << std::endl;
136-
}
156+
ASSERT_LT(ros::Time::now(), deadline) << test_scope_ << "Initial map timeout";
137157
}
138158
pub_map_.publish(map_);
139159
std::cerr << test_scope_ << ros::Time::now() << " Map applied." << std::endl;
140160

161+
while (ros::ok() && !map_local_)
162+
{
163+
ros::spinOnce();
164+
rate.sleep();
165+
ASSERT_LT(ros::Time::now(), deadline) << test_scope_ << "Initial local map timeout";
166+
}
167+
141168
while (ros::ok() && !costmap_)
142169
{
143170
ros::spinOnce();
144171
rate.sleep();
145-
const ros::Time now = ros::Time::now();
146-
if (now > deadline)
147-
{
148-
FAIL() << test_scope_ << now << " SetUp: costmap timeout" << std::endl;
149-
}
172+
ASSERT_LT(ros::Time::now(), deadline) << test_scope_ << "Initial costmap timeout";
150173
}
151174

152175
std_srvs::EmptyRequest req;
@@ -167,6 +190,10 @@ class Navigate : public ::testing::Test
167190
}
168191
void cbMapLocal(const nav_msgs::OccupancyGrid::ConstPtr& msg)
169192
{
193+
if (map_local_)
194+
{
195+
return;
196+
}
170197
map_local_.reset(new nav_msgs::OccupancyGrid(*msg));
171198
std::cerr << test_scope_ << msg->header.stamp << " Local map received." << std::endl;
172199
}
@@ -198,11 +225,22 @@ class Navigate : public ::testing::Test
198225
}
199226
void pubMapLocal()
200227
{
201-
if (map_local_)
228+
if (!map_local_)
202229
{
203-
pub_map_local_.publish(map_local_);
204-
if ((local_map_apply_cnt_++) % 30 == 0)
205-
std::cerr << test_scope_ << " Local map applied." << std::endl;
230+
return;
231+
}
232+
pub_map_local_.publish(map_local_);
233+
if ((local_map_apply_cnt_++) % 30 == 0)
234+
{
235+
int num_occupied = 0;
236+
for (const auto& c : map_local_->data)
237+
{
238+
if (c == 100)
239+
{
240+
num_occupied++;
241+
}
242+
}
243+
std::cerr << test_scope_ << " Local map applied. occupied grids:" << num_occupied << std::endl;
206244
}
207245
}
208246
tf2::Stamped<tf2::Transform> lookupRobotTrans(const ros::Time& now)
@@ -557,6 +595,16 @@ TEST_F(Navigate, GoalIsInRockRecovered)
557595
ASSERT_TRUE(static_cast<bool>(map_));
558596
ASSERT_TRUE(static_cast<bool>(map_local_));
559597

598+
for (int x = 10; x <= 16; ++x)
599+
{
600+
for (int y = 22; y <= 26; ++y)
601+
{
602+
const int pos = x + y * map_local_->info.width;
603+
map_local_->data[pos] = 100;
604+
}
605+
}
606+
pubMapLocal();
607+
560608
nav_msgs::Path path;
561609
path.poses.resize(1);
562610
path.header.frame_id = "map";
@@ -566,19 +614,12 @@ TEST_F(Navigate, GoalIsInRockRecovered)
566614
path.poses[0].pose.orientation.w = 1.0;
567615
pub_patrol_nodes_.publish(path);
568616

569-
for (int x = 12; x <= 14; ++x)
570-
{
571-
for (int y = 24; y <= 26; ++y)
572-
{
573-
const int pos = x + y * map_local_->info.width;
574-
map_local_->data[pos] = 100;
575-
}
576-
}
577617
waitForPlannerStatus("Got stuck", planner_cspace_msgs::PlannerStatus::PATH_NOT_FOUND);
618+
ASSERT_FALSE(::testing::Test::HasFailure());
578619

579-
for (int x = 12; x <= 14; ++x)
620+
for (int x = 10; x <= 16; ++x)
580621
{
581-
for (int y = 24; y <= 26; ++y)
622+
for (int y = 22; y <= 26; ++y)
582623
{
583624
const int pos = x + y * map_local_->info.width;
584625
map_local_->data[pos] = 0;
@@ -593,6 +634,16 @@ TEST_F(Navigate, RobotIsInRockOnRecovered)
593634
ASSERT_TRUE(static_cast<bool>(map_));
594635
ASSERT_TRUE(static_cast<bool>(map_local_));
595636

637+
for (int x = 21; x <= 28; ++x)
638+
{
639+
for (int y = 2; y <= 8; ++y)
640+
{
641+
const int pos = x + y * map_local_->info.width;
642+
map_local_->data[pos] = 100;
643+
}
644+
}
645+
pubMapLocal();
646+
596647
nav_msgs::Path path;
597648
path.poses.resize(1);
598649
path.header.frame_id = "map";
@@ -602,19 +653,12 @@ TEST_F(Navigate, RobotIsInRockOnRecovered)
602653
path.poses[0].pose.orientation.w = 1.0;
603654
pub_patrol_nodes_.publish(path);
604655

605-
for (int x = 23; x <= 26; ++x)
606-
{
607-
for (int y = 4; y <= 6; ++y)
608-
{
609-
const int pos = x + y * map_local_->info.width;
610-
map_local_->data[pos] = 100;
611-
}
612-
}
613656
waitForPlannerStatus("Got stuck", planner_cspace_msgs::PlannerStatus::IN_ROCK);
657+
ASSERT_FALSE(::testing::Test::HasFailure());
614658

615-
for (int x = 23; x <= 26; ++x)
659+
for (int x = 21; x <= 28; ++x)
616660
{
617-
for (int y = 4; y <= 6; ++y)
661+
for (int y = 2; y <= 8; ++y)
618662
{
619663
const int pos = x + y * map_local_->info.width;
620664
map_local_->data[pos] = 0;

planner_cspace/test/test/navigation_compat_rostest.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<env name="GCOV_PREFIX" value="/tmp/gcov/planner_cspace_navigation_compat" />
44
<param name="neonavigation_compatible" value="0" />
55

6-
<test test-name="test_navigate" pkg="planner_cspace" type="test_navigate" time-limit="200.0">
6+
<test test-name="test_navigate_compat" pkg="planner_cspace" type="test_navigate" time-limit="200.0">
77
<remap from="patrol_nodes" to="/patrol/path" />
88
<remap from="forget_planning_cost" to="/planner_3d/forget" />
99
<remap from="map" to="/map" />

planner_cspace/test/test/navigation_remember_rostest.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<env name="GCOV_PREFIX" value="/tmp/gcov/planner_cspace_navigation_remember" />
77
<param name="neonavigation_compatible" value="1" />
88

9-
<test test-name="test_navigate" pkg="planner_cspace" type="test_navigate_remember" time-limit="200.0" />
9+
<test test-name="test_navigate_remember" pkg="planner_cspace" type="test_navigate_remember" time-limit="200.0" />
1010

1111
<node pkg="costmap_cspace" type="costmap_3d" name="costmap_3d">
1212
<rosparam param="footprint">[[0.2, -0.1], [0.2, 0.1], [-0.2, 0.1], [-0.2, -0.1]]</rosparam>

planner_cspace/test/test/navigation_rostest.test

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<env name="GCOV_PREFIX" value="/tmp/gcov/planner_cspace_navigation_$(arg antialias_start)_$(arg fast_map_update)_$(arg with_tolerance)" />
77
<param name="neonavigation_compatible" value="1" />
88

9-
<test test-name="test_navigate" pkg="planner_cspace" type="test_navigate" time-limit="200.0" />
9+
<test test-name="test_navigate_$(arg antialias_start)_$(arg fast_map_update)_$(arg with_tolerance)" pkg="planner_cspace" type="test_navigate" time-limit="200.0" />
1010

1111
<node pkg="costmap_cspace" type="costmap_3d" name="costmap_3d">
1212
<rosparam param="footprint">[[0.2, -0.1], [0.2, 0.1], [-0.2, 0.1], [-0.2, -0.1]]</rosparam>
@@ -29,7 +29,6 @@
2929
<param name="max_vel" value="0.1" />
3030
<param name="max_ang_vel" value="0.3" />
3131
<param name="goal_tolerance_lin" value="0.025" />
32-
<param name="sw_wait" value="0.2" />
3332
<param name="antialias_start" value="$(arg antialias_start)" />
3433
<param name="fast_map_update" value="$(arg fast_map_update)" />
3534
</node>
@@ -41,7 +40,7 @@
4140

4241
<param name="curv_forward" value="0.1" />
4342
<param name="look_forward" value="0.0" />
44-
<param name="k_dist" value="4.5" />
43+
<param name="k_dist" value="5.5" />
4544
<param name="k_ang" value="3.0" />
4645
<param name="k_avel" value="4.0" />
4746

0 commit comments

Comments
 (0)