35 #include <gtest/gtest.h>
39 #include <costmap_cspace_msgs/MapMetaData3D.h>
80 const int local_range = 10;
81 omp_set_num_threads(2);
83 costmap_cspace_msgs::MapMetaData3D map_info;
87 map_info.linear_resolution = 1.0;
88 map_info.angular_resolution = M_PI * 2 /
angle_;
98 Astar::Gridmap<char, 0x40> cm;
99 Astar::Gridmap<char, 0x80> cm_hyst;
108 cm_hyst.reset(size3d);
121 .local_range = local_range,
124 .resolution = map_info.linear_resolution,
144 for (
int x = 0; x <
w_; x++)
154 const std::string& msg)
const
166 ec_[0] * (p -
e_).norm(),
178 for (
int y = 0; y <
h_; y++)
180 for (
int x = 0; x <
w_; x++)
184 if (::testing::Test::HasFatalFailure())
194 public ::testing::WithParamInterface<std::vector<Vec3>>
199 UpdateWithTemporaryObstacles,
216 std::vector<Vec3>()));
223 debugOutput(dm_, cm_rough_, s_, e_);
227 debugOutput(dm_, cm_rough_, s_, e_);
239 dm_.update(
Astar::Vec(1000, 1000, 0), e_, rect);
240 dm_.update(
Astar::Vec(-1000, 1000, 0), e_, rect);
241 dm_.update(
Astar::Vec(-1000, -1000, 0), e_, rect);
242 dm_.update(
Astar::Vec(1000, -1000, 0), e_, rect);
252 dm_.update(s_,
Astar::Vec(1000, 1000, 0), rect);
253 dm_.update(s_,
Astar::Vec(-1000, 1000, 0), rect);
254 dm_.update(s_,
Astar::Vec(-1000, -1000, 0), rect);
255 dm_.update(s_,
Astar::Vec(1000, -1000, 0), rect);
260 const std::vector<Vec3> obstacles = GetParam();
263 for (
int from_y = 0; from_y < h_; from_y++)
265 for (
int from_x = 0; from_x < w_; from_x++)
267 const std::string from(xyStr(from_x, from_y));
268 for (
int to_y = from_y; to_y < h_; to_y++)
270 for (
int to_x = from_x; to_x < w_; to_x++)
272 const std::string to(xyStr(to_x, to_y));
276 for (
const Vec3& obstacle : obstacles)
278 if (from_x < obstacle[0] && obstacle[0] < to_x &&
279 from_y < obstacle[1] && obstacle[1] < to_y)
281 cm_rough_[obstacle] = 100;
290 for (
int i = 0; i < 5; i++)
295 Vec3(from_x, from_y, 0),
Vec3(to_x, to_y, 0)));
296 if (!
validate(
"update " + from +
"-" + to))
298 debugOutput(dm_, cm_rough_, s_, e_);
333 costmap_cspace_msgs::MapMetaData3D map_info;
335 map_info.height =
h_;
337 map_info.linear_resolution = 1.0;
338 map_info.angular_resolution = M_PI * 2 /
angle_;
344 omp_set_num_threads(1);
349 Astar::Gridmap<char, 0x40> cm;
350 Astar::Gridmap<char, 0x80> cm_hyst;
359 cm_hyst.reset(size3d);
374 .resolution = map_info.linear_resolution,
385 const float tolerance = 0.4;
387 const int range_overshoot = range_ + local_range_ + longcut_range_ + search_range_;
389 const auto validate = [
this,
s, e, tolerance, range_overshoot]()
391 for (
int y = 0; y < h_; y++)
393 for (
int x = 0; x < w_; x++)
396 const float cost = dm_[p];
397 const float d = (p - e).norm();
398 const float d_from_start = (p -
s).norm();
399 if (x <
s[0] || d_from_start <= range_overshoot)
401 ASSERT_NEAR(ec_[0] *
d, cost, tolerance) << xyStr(x, y);
403 else if (d_from_start > range_overshoot)
405 ASSERT_EQ(std::numeric_limits<float>::max(), cost) << xyStr(x, y);
413 SCOPED_TRACE(
"After create");
416 if (::testing::Test::HasFatalFailure())
417 debugOutput(dm_, cm_rough_,
s, e);
424 SCOPED_TRACE(
"After update");
427 if (::testing::Test::HasFatalFailure())
428 debugOutput(dm_, cm_rough_,
s, e);
436 const float tolerance = 0.4;
438 const int range_overshoot = range_ + local_range_ + longcut_range_ + search_range_;
439 const auto validate = [
this,
s, e, tolerance, range_overshoot](
const int obstacle_x)
441 for (
int y = 0; y < h_; y++)
443 for (
int x = 0; x < w_; x++)
446 const float cost = dm_[p];
447 const float d = (p - e).norm();
448 const float d_from_start = (p -
s).norm();
449 if ((x <
s[0] || d_from_start < range_overshoot) && x < obstacle_x)
451 ASSERT_NEAR(ec_[0] *
d, cost, tolerance) << xyStr(x, y);
453 else if (x > obstacle_x)
455 ASSERT_EQ(std::numeric_limits<float>::max(), cost) << xyStr(x, y);
463 SCOPED_TRACE(
"No obstacle");
467 for (
int y = 0; y < h_; y++)
476 SCOPED_TRACE(
"Obstacle at x=5");
479 if (::testing::Test::HasFatalFailure())
481 debugOutput(dm_, cm_rough_,
s, e);
492 SCOPED_TRACE(
"No obstacle");
495 if (::testing::Test::HasFatalFailure())
497 debugOutput(dm_, cm_rough_,
s, e);
506 const float tolerance = 0.4;
508 const int range_overshoot = range_ + local_range_ + longcut_range_ + search_range_;
512 for (
int y = 0; y < h_; y++)
514 for (
int x = 0; x < w_; x++)
517 const float cost = dm_[p];
518 const float d = (p - e).norm();
519 const float d_from_start = (p -
s).norm();
520 if (x <
s[0] || d_from_start <= range_overshoot)
522 ASSERT_NEAR(ec_[0] *
d, cost, tolerance) << xyStr(x, y);
524 else if (d_from_start > range_overshoot)
526 ASSERT_EQ(std::numeric_limits<float>::max(), cost) << xyStr(x, y);
535 SCOPED_TRACE(
"After create");
537 if (::testing::Test::HasFatalFailure())
539 debugOutput(dm_, cm_rough_,
s, e);
548 SCOPED_TRACE(
"After update 1");
550 if (::testing::Test::HasFatalFailure())
552 debugOutput(dm_, cm_rough_,
s, e);
561 SCOPED_TRACE(
"After update 2");
563 if (::testing::Test::HasFatalFailure())
565 debugOutput(dm_, cm_rough_,
s, e);
574 SCOPED_TRACE(
"After update 3");
576 if (::testing::Test::HasFatalFailure())
578 debugOutput(dm_, cm_rough_,
s, e);
585 int main(
int argc,
char** argv)
587 testing::InitGoogleTest(&argc, argv);
589 return RUN_ALL_TESTS();