Skip to content

Commit f5406b4

Browse files
committed
feat: add getArcCoordinatesUsingWaypoints to enable custom waypoint usage
Signed-off-by: Mehmet Dogru <42mehmetdogru42@gmail.com>
1 parent c84775e commit f5406b4

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

autoware_lanelet2_extension/include/autoware_lanelet2_extension/utility/utilities.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ double getLaneletLength3d(const lanelet::ConstLanelets & lanelet_sequence);
8686
lanelet::ArcCoordinates getArcCoordinates(
8787
const lanelet::ConstLanelets & lanelet_sequence, const geometry_msgs::msg::Pose & pose);
8888

89+
/**
90+
* @brief This function uses custom centerline for the lanelet if exists defined with the attribute
91+
* "waypoints" instead of centerline associated to the lanelet
92+
*/
93+
lanelet::ArcCoordinates getArcCoordinatesConsideringWaypoints(
94+
const lanelet::ConstLanelets & lanelet_sequence, const geometry_msgs::msg::Pose & pose,
95+
const lanelet::LaneletMapConstPtr & lanelet_map_ptr);
96+
8997
lanelet::ConstLineString3d getClosestSegment(
9098
const lanelet::BasicPoint2d & search_pt, const lanelet::ConstLineString3d & linestring);
9199

autoware_lanelet2_extension/lib/utilities.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,36 @@ lanelet::ArcCoordinates getArcCoordinates(
675675
return arc_coordinates;
676676
}
677677

678+
lanelet::ArcCoordinates getArcCoordinatesConsideringWaypoints(
679+
const lanelet::ConstLanelets & lanelet_sequence, const geometry_msgs::msg::Pose & pose,
680+
const lanelet::LaneletMapConstPtr & lanelet_map_ptr)
681+
{
682+
lanelet::ConstLanelet closest_lanelet;
683+
lanelet::utils::query::getClosestLanelet(lanelet_sequence, pose, &closest_lanelet);
684+
685+
double length = 0;
686+
lanelet::ArcCoordinates arc_coordinates;
687+
for (const auto & llt : lanelet_sequence) {
688+
ConstLineString2d centerline_2d;
689+
if (llt.hasAttribute("waypoints")) {
690+
const auto waypoints_id = llt.attribute("waypoints").asId().value();
691+
centerline_2d = lanelet::utils::to2D(lanelet_map_ptr->lineStringLayer.get(waypoints_id));
692+
} else {
693+
centerline_2d = lanelet::utils::to2D(llt.centerline());
694+
}
695+
696+
if (llt == closest_lanelet) {
697+
const auto lanelet_point = lanelet::utils::conversion::toLaneletPoint(pose.position);
698+
arc_coordinates = lanelet::geometry::toArcCoordinates(
699+
centerline_2d, lanelet::utils::to2D(lanelet_point).basicPoint());
700+
arc_coordinates.length += length;
701+
break;
702+
}
703+
length += static_cast<double>(boost::geometry::length(centerline_2d));
704+
}
705+
return arc_coordinates;
706+
}
707+
678708
lanelet::ConstLineString3d getClosestSegment(
679709
const lanelet::BasicPoint2d & search_pt, const lanelet::ConstLineString3d & linestring)
680710
{

0 commit comments

Comments
 (0)