Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/at-wat/neonavigation into…
Browse files Browse the repository at this point in the history
… avoid-expanding-surrrounded-cells
  • Loading branch information
nhatao committed Oct 31, 2023
2 parents 7840707 + e632876 commit 40ad6a1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 9 additions & 5 deletions planner_cspace/src/grid_astar_model_3dof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ float GridAstarModel3D::euclidCostRough(const Vec& v) const
float GridAstarModel3D::cost(
const Vec& cur, const Vec& next, const std::vector<VecWithCost>& start, const Vec& goal) const
{
if ((cm_[cur] > 99) || (cm_[next] > 99))
{
return -1;
}
Vec d_raw = next - cur;
d_raw.cycle(map_info_.angle);
const Vec d = d_raw;
Expand All @@ -168,18 +172,18 @@ float GridAstarModel3D::cost(
Vec pos = cur;
for (int i = 0; i < std::abs(d[2]); i++)
{
pos[2] += dir;
if (pos[2] < 0)
pos[2] += map_info_.angle;
else if (pos[2] >= static_cast<int>(map_info_.angle))
pos[2] -= map_info_.angle;
const auto c = cm_[pos];
if (c > 99)
return -1;
if (c >= cc_.turn_penalty_cost_threshold_)
{
sum += c;
}
pos[2] += dir;
if (pos[2] < 0)
pos[2] += map_info_.angle;
else if (pos[2] >= static_cast<int>(map_info_.angle))
pos[2] -= map_info_.angle;
}
const float turn_cost_ratio = cc_.weight_costmap_turn_ / 100.0;
const float turn_heuristic_cost_ratio =
Expand Down
20 changes: 20 additions & 0 deletions planner_cspace/test/src/test_planner_3d_cost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TEST(GridAstarModel3D, Cost)
cc.max_vel_ = 1.0;
cc.max_ang_vel_ = 1.0;
cc.angle_resolution_aspect_ = 1.0;
cc.turn_penalty_cost_threshold_ = 0;

GridAstarModel3D model(
map_info,
Expand All @@ -91,6 +92,25 @@ TEST(GridAstarModel3D, Cost)
EXPECT_LT(c_straight, c_curve);
EXPECT_LT(c_straight, c_drift);
EXPECT_LT(c_straight, c_drift_curve);

// These tests are added to confirm that some bugs are fixed by https://github.com/at-wat/neonavigation/pull/725
const GridAstarModel3D::Vec start2(5, 5, 0);
const GridAstarModel3D::Vec occupied_waypoint(10, 5, 0);
const GridAstarModel3D::Vec goal2(10, 5, 3);
cm[occupied_waypoint] = 100;
// The cost toward the occupied cell should be negative.
EXPECT_LT(model.cost(start2, occupied_waypoint, {GridAstarModel3D::VecWithCost(start2)}, occupied_waypoint), 0);
// The cost from the occupied cell should be negative.
EXPECT_LT(model.cost(occupied_waypoint, goal2, {GridAstarModel3D::VecWithCost(occupied_waypoint)}, goal2), 0);

const GridAstarModel3D::Vec start3(10, 20, 0);
cm[start3] = 99;
const GridAstarModel3D::Vec waypoint3(10, 20, 3);
const GridAstarModel3D::Vec goal3(10, 20, 6);
// The cost between start3 and waypoint3 is larger than the cost between waypoint3 and goal3 because start3
// has a penalty.
EXPECT_GT(model.cost(start3, waypoint3, {GridAstarModel3D::VecWithCost(start3)}, waypoint3),
model.cost(waypoint3, goal3, {GridAstarModel3D::VecWithCost(waypoint3)}, goal3));
}
} // namespace planner_3d
} // namespace planner_cspace
Expand Down

0 comments on commit 40ad6a1

Please sign in to comment.