Skip to content

Commit

Permalink
Fix routing from crosswalk (autowarefoundation#767)
Browse files Browse the repository at this point in the history
Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
  • Loading branch information
wep21 authored and mitsudome-r committed Sep 25, 2020
1 parent f6121a7 commit 2b94690
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,47 @@ void insertMarkerArray(
a1->markers.insert(a1->markers.end(), a2.markers.begin(), a2.markers.end());
}

std::vector<std::pair<double, lanelet::Lanelet>> excludeSubtypeLaneletsWithDistance(
const std::vector<std::pair<double, lanelet::Lanelet>> & lls, const char subtype[])
{
std::vector<std::pair<double, lanelet::Lanelet>> exclude_subtype_lanelets;

for (const auto & ll : lls) {
if (ll.second.hasAttribute(lanelet::AttributeName::Subtype)) {
lanelet::Attribute attr = ll.second.attribute(lanelet::AttributeName::Subtype);
if (attr.value() != subtype) {
exclude_subtype_lanelets.push_back(ll);
}
}
}

return exclude_subtype_lanelets;
}

bool getClosestLanelet(
const geometry_msgs::Pose & search_pose, const lanelet::LaneletMapPtr & lanelet_map_ptr_,
lanelet::Lanelet * closest_lanelet, double distance_thresh)
{
lanelet::BasicPoint2d search_point(search_pose.position.x, search_pose.position.y);
std::vector<std::pair<double, lanelet::Lanelet>> nearest_lanelet =
lanelet::geometry::findNearest(lanelet_map_ptr_->laneletLayer, search_point, 1);
if (nearest_lanelet.empty()) {
const auto nearest_road_lanelet =
excludeSubtypeLaneletsWithDistance(nearest_lanelet, lanelet::AttributeValueString::Crosswalk);
if (nearest_road_lanelet.empty()) {
ROS_ERROR_STREAM(
"Failed to find the closest lane!" << std::endl
<< "search point: " << toString(search_pose) << std::endl);
return false;
}
if (nearest_lanelet.front().first > distance_thresh) {
if (nearest_road_lanelet.front().first > distance_thresh) {
ROS_ERROR_STREAM(
"Closest lane is too far away!" << std::endl
<< "search point: " << toString(search_pose) << std::endl
<< "lane id: " << nearest_lanelet.front().second.id());
return false;
}

*closest_lanelet = nearest_lanelet.front().second;
*closest_lanelet = nearest_road_lanelet.front().second;

return true;
}

0 comments on commit 2b94690

Please sign in to comment.