Skip to content

Commit b831849

Browse files
feat(obstacle cruise): reduce computation cost (#7040)
* reduce computation cost Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
1 parent 173aae4 commit b831849

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

planning/obstacle_cruise_planner/include/obstacle_cruise_planner/polygon_utils.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ std::vector<PointWithStamp> getCollisionPoints(
4747
const std::vector<TrajectoryPoint> & traj_points, const std::vector<Polygon2d> & traj_polygons,
4848
const rclcpp::Time & obstacle_stamp, const PredictedPath & predicted_path, const Shape & shape,
4949
const rclcpp::Time & current_time, const bool is_driving_forward,
50-
std::vector<size_t> & collision_index,
51-
const double max_lat_dist = std::numeric_limits<double>::max(),
50+
std::vector<size_t> & collision_index, const double max_dist = std::numeric_limits<double>::max(),
5251
const double max_prediction_time_for_collision_check = std::numeric_limits<double>::max());
5352

5453
} // namespace polygon_utils

planning/obstacle_cruise_planner/src/node.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,11 @@ ObstacleCruisePlannerNode::createCollisionPointsForInsideCruiseObstacle(
10791079
std::vector<size_t> collision_index;
10801080
const auto collision_points = polygon_utils::getCollisionPoints(
10811081
traj_points, traj_polys, obstacle.stamp, resampled_predicted_path, obstacle.shape, now(),
1082-
is_driving_forward_, collision_index);
1082+
is_driving_forward_, collision_index,
1083+
calcObstacleMaxLength(obstacle.shape) + p.decimate_trajectory_step_length +
1084+
std::hypot(
1085+
vehicle_info_.vehicle_length_m,
1086+
vehicle_info_.vehicle_width_m * 0.5 + p.max_lat_margin_for_cruise));
10831087
return collision_points;
10841088
}
10851089

@@ -1119,7 +1123,10 @@ ObstacleCruisePlannerNode::createCollisionPointsForOutsideCruiseObstacle(
11191123
const auto collision_points = polygon_utils::getCollisionPoints(
11201124
traj_points, traj_polys, obstacle.stamp, resampled_predicted_path, obstacle.shape, now(),
11211125
is_driving_forward_, collision_index,
1122-
vehicle_info_.vehicle_width_m + p.max_lat_margin_for_cruise,
1126+
calcObstacleMaxLength(obstacle.shape) + p.decimate_trajectory_step_length +
1127+
std::hypot(
1128+
vehicle_info_.vehicle_length_m,
1129+
vehicle_info_.vehicle_width_m * 0.5 + p.max_lat_margin_for_cruise),
11231130
p.max_prediction_time_for_collision_check);
11241131
if (collision_points.empty()) {
11251132
// Ignore vehicle obstacles outside the trajectory without collision
@@ -1196,7 +1203,11 @@ std::optional<StopObstacle> ObstacleCruisePlannerNode::createStopObstacle(
11961203
std::vector<size_t> collision_index;
11971204
const auto collision_points = polygon_utils::getCollisionPoints(
11981205
traj_points, traj_polys, obstacle.stamp, resampled_predicted_path, obstacle.shape, now(),
1199-
is_driving_forward_, collision_index);
1206+
is_driving_forward_, collision_index,
1207+
calcObstacleMaxLength(obstacle.shape) + p.decimate_trajectory_step_length +
1208+
std::hypot(
1209+
vehicle_info_.vehicle_length_m,
1210+
vehicle_info_.vehicle_width_m * 0.5 + p.max_lat_margin_for_stop));
12001211
if (collision_points.empty()) {
12011212
RCLCPP_INFO_EXPRESSION(
12021213
get_logger(), enable_debug_info_,

planning/obstacle_cruise_planner/src/polygon_utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ PointWithStamp calcNearestCollisionPoint(
4444
return collision_points.at(min_idx);
4545
}
4646

47-
// NOTE: max_lat_dist is used for efficient calculation to suppress boost::geometry's polygon
47+
// NOTE: max_dist is used for efficient calculation to suppress boost::geometry's polygon
4848
// calculation.
4949
std::optional<std::pair<size_t, std::vector<PointWithStamp>>> getCollisionIndex(
5050
const std::vector<TrajectoryPoint> & traj_points, const std::vector<Polygon2d> & traj_polygons,
5151
const geometry_msgs::msg::Pose & object_pose, const rclcpp::Time & object_time,
52-
const Shape & object_shape, const double max_lat_dist = std::numeric_limits<double>::max())
52+
const Shape & object_shape, const double max_dist = std::numeric_limits<double>::max())
5353
{
5454
const auto obj_polygon = tier4_autoware_utils::toPolygon2d(object_pose, object_shape);
5555
for (size_t i = 0; i < traj_polygons.size(); ++i) {
5656
const double approximated_dist =
5757
tier4_autoware_utils::calcDistance2d(traj_points.at(i).pose, object_pose);
58-
if (approximated_dist > max_lat_dist) {
58+
if (approximated_dist > max_dist) {
5959
continue;
6060
}
6161

0 commit comments

Comments
 (0)