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

HdMapUtils refactor lanelet_wrapper::distance::distanceToStopLine #1538

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

abco20
Copy link
Contributor

@abco20 abco20 commented Feb 27, 2025

Description

Abstract

This is the partial PR of the HdMapUtils refactor (PR 2/6) ( #1478 )

Details

Replace usage of HdMapUtils::getDistanceToStopLine with non-member function lanelet_wrapper::distance::distanceToStopLine.

In the distanceToStopLine function, instead of adding all values to std::set and then using the first element, only the smallest value is stored.

before:

if (collision_point) {
collision_points.insert(collision_point.value());
}
}
if (collision_points.empty()) {
return std::nullopt;
}
return *collision_points.begin();

after:

if (const auto & collision_point = route_spline.getCollisionPointIn2D(stop_line_points)) {
if (not min_distance.has_value() or collision_point.value() < min_distance.value()) {
min_distance = collision_point;
}
}
}
return min_distance;

References

Destructive Changes

The arguments of traffic_simulator::distanceToStopLine have been changed.

before

auto distanceToStopLine(
  const traffic_simulator_msgs::msg::WaypointsArray & waypoints_array,
  const lanelet::Id target_stop_line_id,
  const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr) -> std::optional<double>;

after

template <typename... Ts>
auto distanceToStopLine(Ts &&... xs)
{
  return lanelet_wrapper::distance::distanceToStopLine(std::forward<decltype(xs)>(xs)...);
}

The definition of lanelet_wrapper::distance::distanceToStopLine, to which this function forwards, is as follows:

auto distanceToStopLine(const lanelet::Ids & route_lanelets, const SplineInterface & route_spline)
  -> std::optional<double>;

auto distanceToStopLine(
  const lanelet::Ids & route_lanelets, const std::vector<Point> & route_waypoints)
  -> std::optional<double>;

auto distanceToStopLine(const std::vector<Point> & route_waypoints, const lanelet::Id stop_line_id)
  -> std::optional<double>;

Migration Guide

The most appropriate overload corresponding to the original distanceToStopLine function call is:

auto distanceToStopLine(const std::vector<Point> & route_waypoints, const lanelet::Id stop_line_id)
  -> std::optional<double>;

Since the third argument hdmap_utils_ptr has been removed, eliminate it from your function calls.

Instead of passing const traffic_simulator_msgs::msg::WaypointsArray & waypoints_array, you should pass const std::vector<Point> & route_waypoints by extracting the waypoints from WaypointsArray msg.

Known Limitations

None.

Copy link

Checklist for reviewers ☑️

All references to "You" in the following text refer to the code reviewer.

  • Is this pull request written in a way that is easy to read from a third-party perspective?
  • Is there sufficient information (background, purpose, specification, algorithm description, list of disruptive changes, and migration guide) in the description of this pull request?
  • If this pull request contains a destructive change, does this pull request contain the migration guide?
  • Labels of this pull request are valid?
  • All unit tests/integration tests are included in this pull request? If you think adding test cases is unnecessary, please describe why and cross out this line.
  • The documentation for this pull request is enough? If you think adding documents for this pull request is unnecessary, please describe why and cross out this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants