Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(path_generator): add path_generator package #9216

Closed

Conversation

mitukou1109
Copy link
Contributor

@mitukou1109 mitukou1109 commented Nov 1, 2024

Description

This PR adds path_generator package, a simplified alternative of behavior_path_planner.

Related links

How was this PR tested?

Psim on a lanelet2 map with waypoints

Screencast.from.2024.11.29.16.11.24.webm

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

@github-actions github-actions bot added the component:planning Route planning, decision-making, and navigation. (auto-assigned) label Nov 1, 2024
Copy link

github-actions bot commented Nov 1, 2024

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

return *this;
}

private:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem several parameters which can be local variables.
IMO, increasing the member variables decreases the readability and maintainability since it's not clear that the variables are used and modified. So please try not to use the member variables as much as possible.

@takayuki5168 takayuki5168 self-requested a review November 1, 2024 07:34
@takayuki5168 takayuki5168 added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Nov 1, 2024

// set yaw to each point
{
auto it = path_points.begin();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in for(here;...

Comment on lines 164 to 214
const auto waypoint_groups = utils::getWaypointGroups(lanelet_sequence, *lanelet_map_ptr_);

double s = 0.;
for (const auto & lanelet : lanelet_sequence) {
std::vector<geometry_msgs::msg::Point> reference_points;
const auto & centerline = lanelet.centerline();

std::optional<size_t> overlapped_waypoint_group_index = std::nullopt;
for (auto it = centerline.begin(); it != centerline.end(); ++it) {
if (s <= s_end) {
const lanelet::Point3d point(*it);
if (s >= s_start) {
for (size_t i = 0; i < waypoint_groups.size(); ++i) {
const auto & [waypoints, interval] = waypoint_groups[i];
if (s >= interval.first && s <= interval.second) {
overlapped_waypoint_group_index = i;
break;
} else if (i == overlapped_waypoint_group_index) {
for (const auto & waypoint : waypoints) {
reference_points.push_back(lanelet::utils::conversion::toGeomMsgPt(waypoint));
}
overlapped_waypoint_group_index = std::nullopt;
}
}
if (!overlapped_waypoint_group_index) {
reference_points.push_back(lanelet::utils::conversion::toGeomMsgPt(point));
}
}
if (it == std::prev(centerline.end())) {
break;
}

const lanelet::Point3d next_point(*std::next(it));
const auto distance = lanelet::geometry::distance2d(point, next_point);
std::optional<double> s_interpolation = std::nullopt;
if (s + distance > s_end) {
s_interpolation = s_end - s;
} else if (s < s_start && s + distance > s_start) {
s_interpolation = s_start - s;
}

if (s_interpolation) {
const auto interpolated_point = lanelet::geometry::interpolatedPointAtDistance(
lanelet::ConstLineString3d{lanelet::InvalId, {point, next_point}}, *s_interpolation);
reference_points.push_back(lanelet::utils::conversion::toGeomMsgPt(interpolated_point));
}
s += distance;
} else {
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: No need to refactor here.

return waypoint_groups;
}

void removeOverlappingPoints(PathWithLaneId & path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitukou1109 Please write unit tests for utils functions. Code quality and reliability is very important for this package. It's okay to add tests in other PR.


void PathGenerator::run()
{
const auto input_data = takeData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each variable in input_data may be nullptr. We should check whether the input_data is valid or not (= whether the input data is ready or not) here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation is now in the updatePlannerData.
I feel checking whether the input_data is valid or not should be before planPath

return std::nullopt;
}

auto path = utils::generateCenterLinePath(planner_data_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

Comment on lines 27 to 38
lanelet::LaneletMapPtr lanelet_map_ptr{nullptr};
lanelet::traffic_rules::TrafficRulesPtr traffic_rules_ptr{nullptr};
lanelet::routing::RoutingGraphPtr routing_graph_ptr{nullptr};

geometry_msgs::msg::Pose current_pose;

autoware_planning_msgs::msg::LaneletRoute::ConstSharedPtr route_ptr{nullptr};

lanelet::ConstLanelets route_lanelets;
lanelet::ConstLanelets preferred_lanelets;
lanelet::ConstLanelets start_lanelets;
lanelet::ConstLanelets goal_lanelets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel these variables do not have to be member variables.

planner_data_.start_lanelets.clear();
planner_data_.goal_lanelets.clear();

if (!planner_data_.route_ptr->segments.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use early return.

Comment on lines 402 to 158
std::vector<std::pair<lanelet::ConstPoints3d, std::pair<double, double>>> getWaypointGroups(
const lanelet::ConstLanelets & lanelet_sequence, const lanelet::LaneletMap & lanelet_map)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: No need to refactor and write a unit test for this function.

path_publisher_->publish(*path);
}

PathGenerator::InputData PathGenerator::takeData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the snake case for all the functions.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 246 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (ddfacd3) to head (f4dfe91).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
planning/autoware_path_generator/src/node.cpp 0.00% 170 Missing ⚠️
planning/autoware_path_generator/src/utils.cpp 0.00% 76 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #9216       +/-   ##
==========================================
- Coverage   29.76%   0.00%   -29.77%     
==========================================
  Files        1444      87     -1357     
  Lines      108686    3866   -104820     
  Branches    42664     671    -41993     
==========================================
- Hits        32352       0    -32352     
+ Misses      73150    3866    -69284     
+ Partials     3184       0     -3184     
Flag Coverage Δ
differential 0.00% <0.00%> (?)
total ?

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mitukou1109 mitukou1109 force-pushed the feat/path_generator branch 5 times, most recently from e0f2caa to d2c2cda Compare November 13, 2024 08:30
@mitukou1109 mitukou1109 force-pushed the feat/path_generator branch 2 times, most recently from 6717500 to 6fe9161 Compare November 22, 2024 09:53
if (
planner_data.preferred_lanelets.front().id() != lanelet.id() &&
exists(planner_data.route_lanelets, lanelet)) {
return lanelet;
Copy link
Contributor

@takayuki5168 takayuki5168 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the first lanelet in the next lanelets is not good as a specification of the utility function.
Let's change the function to get_next_lanelets_within_route, and the node side will use the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next lanelet in a route should be single.
So, please add the error log like

RCLCPP_WARN(rclcpp::get_logger("path_generator.utils"), "The multiple next lanelets in a route are found not as expected. Internal calculation might have failed.");

when there are multiple next lanelets.

Returning the first lanelet in this case is fine.

Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
Signed-off-by: mitukou1109 <[email protected]>
@github-actions github-actions bot added the type:documentation Creating or refining documentation. (auto-assigned) label Dec 23, 2024
@takayuki5168 takayuki5168 added the run:deploy-docs Mark for deploy-docs action generation. (used-by-ci) label Dec 23, 2024
@takayuki5168
Copy link
Contributor

New PR was created, so I close this PR.
autowarefoundation/autoware.core#138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:planning Route planning, decision-making, and navigation. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) run:deploy-docs Mark for deploy-docs action generation. (used-by-ci) type:documentation Creating or refining documentation. (auto-assigned)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants