@@ -96,29 +96,53 @@ class Navigate : public ::testing::Test
96
96
97
97
virtual void SetUp ()
98
98
{
99
- test_scope_ = " [" + std::to_string (getpid ()) + " ] " ;
99
+ test_scope_ =
100
+ " [" + std::to_string (getpid ()) + " /" +
101
+ ::testing::UnitTest::GetInstance ()->current_test_info()->name() + "] ";
100
102
101
- srv_forget_.waitForExistence (ros::Duration (10.0 ));
102
103
ros::Rate rate (10.0 );
103
104
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
+
104
133
geometry_msgs::PoseWithCovarianceStamped pose;
105
134
pose.header .frame_id = " map" ;
106
135
pose.pose .pose .position .x = 2.5 ;
107
136
pose.pose .pose .position .y = 0.45 ;
108
137
pose.pose .pose .orientation .z = 1.0 ;
109
138
pub_initial_pose_.publish (pose);
110
139
111
- const ros::Time deadline = ros::Time::now () + ros::Duration (15 );
112
-
113
140
while (ros::ok ())
114
141
{
115
142
ros::spinOnce ();
116
143
rate.sleep ();
117
144
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" ;
122
146
if (tfbuf_.canTransform (" map" , " base_link" , now, ros::Duration (0.5 )))
123
147
{
124
148
break ;
@@ -129,24 +153,23 @@ class Navigate : public ::testing::Test
129
153
{
130
154
ros::spinOnce ();
131
155
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" ;
137
157
}
138
158
pub_map_.publish (map_);
139
159
std::cerr << test_scope_ << ros::Time::now () << " Map applied." << std::endl;
140
160
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
+
141
168
while (ros::ok () && !costmap_)
142
169
{
143
170
ros::spinOnce ();
144
171
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" ;
150
173
}
151
174
152
175
std_srvs::EmptyRequest req;
@@ -167,6 +190,10 @@ class Navigate : public ::testing::Test
167
190
}
168
191
void cbMapLocal (const nav_msgs::OccupancyGrid::ConstPtr& msg)
169
192
{
193
+ if (map_local_)
194
+ {
195
+ return ;
196
+ }
170
197
map_local_.reset (new nav_msgs::OccupancyGrid (*msg));
171
198
std::cerr << test_scope_ << msg->header .stamp << " Local map received." << std::endl;
172
199
}
@@ -198,11 +225,22 @@ class Navigate : public ::testing::Test
198
225
}
199
226
void pubMapLocal ()
200
227
{
201
- if (map_local_)
228
+ if (! map_local_)
202
229
{
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;
206
244
}
207
245
}
208
246
tf2::Stamped<tf2::Transform> lookupRobotTrans (const ros::Time& now)
@@ -557,6 +595,16 @@ TEST_F(Navigate, GoalIsInRockRecovered)
557
595
ASSERT_TRUE (static_cast <bool >(map_));
558
596
ASSERT_TRUE (static_cast <bool >(map_local_));
559
597
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
+
560
608
nav_msgs::Path path;
561
609
path.poses .resize (1 );
562
610
path.header .frame_id = " map" ;
@@ -566,19 +614,12 @@ TEST_F(Navigate, GoalIsInRockRecovered)
566
614
path.poses [0 ].pose .orientation .w = 1.0 ;
567
615
pub_patrol_nodes_.publish (path);
568
616
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
- }
577
617
waitForPlannerStatus (" Got stuck" , planner_cspace_msgs::PlannerStatus::PATH_NOT_FOUND);
618
+ ASSERT_FALSE (::testing::Test::HasFailure ());
578
619
579
- for (int x = 12 ; x <= 14 ; ++x)
620
+ for (int x = 10 ; x <= 16 ; ++x)
580
621
{
581
- for (int y = 24 ; y <= 26 ; ++y)
622
+ for (int y = 22 ; y <= 26 ; ++y)
582
623
{
583
624
const int pos = x + y * map_local_->info .width ;
584
625
map_local_->data [pos] = 0 ;
@@ -593,6 +634,16 @@ TEST_F(Navigate, RobotIsInRockOnRecovered)
593
634
ASSERT_TRUE (static_cast <bool >(map_));
594
635
ASSERT_TRUE (static_cast <bool >(map_local_));
595
636
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
+
596
647
nav_msgs::Path path;
597
648
path.poses .resize (1 );
598
649
path.header .frame_id = " map" ;
@@ -602,19 +653,12 @@ TEST_F(Navigate, RobotIsInRockOnRecovered)
602
653
path.poses [0 ].pose .orientation .w = 1.0 ;
603
654
pub_patrol_nodes_.publish (path);
604
655
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
- }
613
656
waitForPlannerStatus (" Got stuck" , planner_cspace_msgs::PlannerStatus::IN_ROCK);
657
+ ASSERT_FALSE (::testing::Test::HasFailure ());
614
658
615
- for (int x = 23 ; x <= 26 ; ++x)
659
+ for (int x = 21 ; x <= 28 ; ++x)
616
660
{
617
- for (int y = 4 ; y <= 6 ; ++y)
661
+ for (int y = 2 ; y <= 8 ; ++y)
618
662
{
619
663
const int pos = x + y * map_local_->info .width ;
620
664
map_local_->data [pos] = 0 ;
0 commit comments