Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

feat(lanelet2_extension): overwriteLaneletsCenterline supports "waypoints" #252

Merged
merged 10 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tmp/lanelet2_extension/docs/lanelet2_format_extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,23 @@ _An example:_
...

```

### Centerline

Note that the following explanation is not related to the Lanelet2 map format but how the Autoware handles the centerline in the Lanelet2 map.

Centerline is defined in Lanelet2 to guide the vehicle. By explicitly setting the centerline in the Lanelet2 map, the ego's planned path follows the centerline.
However, based on the current Autoware's usage of the centerline, there are several limitations.

- The object's predicted path also follows the centerline.
- This may adversely affect the decision making of planning modules since the centerline is supposed to be used only by the ego's path planning.
- The coordinate transformation on the lane's frenet frame cannot be calculated correctly.
- For example, when the lateral distance between the actual road's centerline and a parked vehicle is calculated, actually the result will be the lateral distance between the (explicit) centerline and the vehicle.

To solve above limitations, the `overwriteLaneletsCenterline` has a `use_waypoints` flag where the centerline in all the lanes is calculated.

- `use_waypoints` is True
- The (explicit) centerline in the Lanelet2 map is converted to the new `waypoints` tag. This `waypoints` is only applied to the ego's path planning.
- Therefore, the above limitations can be solved, but the Autoware's usage of the centerline may be hard to understand.
- `use_waypoints` is False
- The (explicit) centerline in the Lanelet2 map is used as it is. Easy to understand the Autoware's usage of the centerline, but we still have above limitations.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lanelet::ConstLanelets getExpandedLanelets(
* doesn't have enough quality
*/
void overwriteLaneletsCenterline(
lanelet::LaneletMapPtr lanelet_map, const double resolution = 5.0,
lanelet::LaneletMapPtr lanelet_map, const double resolution, const bool use_waypoints,
const bool force_overwrite = false);

lanelet::ConstLanelets getConflictingLanelets(
Expand Down
20 changes: 18 additions & 2 deletions tmp/lanelet2_extension/lib/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,28 @@ lanelet::ConstLanelets getExpandedLanelets(
}

void overwriteLaneletsCenterline(
lanelet::LaneletMapPtr lanelet_map, const double resolution, const bool force_overwrite)
lanelet::LaneletMapPtr lanelet_map, const double resolution, const bool use_waypoints,
Copy link
Member

Choose a reason for hiding this comment

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

Just as a comment, since the third argument of the function has changed it's meaning, we should make sure that any other code that uses force_overwrite argument should be merged at the same time as this PR.

Copy link
Member

Choose a reason for hiding this comment

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

@takayuki5168 Have you checked if the codes in autoware.universe and autoware_tools are fine with the modification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review.
Yes, I've already checked. The following PR is the change for the universe.
https://github.com/autowarefoundation/autoware.universe/pull/7480/files

const bool force_overwrite)
{
for (auto & lanelet_obj : lanelet_map->laneletLayer) {
if (force_overwrite || !lanelet_obj.hasCustomCenterline()) {
if (force_overwrite) {
const auto fine_center_line = generateFineCenterline(lanelet_obj, resolution);
lanelet_obj.setCenterline(fine_center_line);
} else {
if (use_waypoints) {
if (lanelet_obj.hasCustomCenterline()) {
const auto & centerline = lanelet_obj.centerline();
lanelet_obj.setAttribute("waypoints", centerline.id());
}

const auto fine_center_line = generateFineCenterline(lanelet_obj, resolution);
lanelet_obj.setCenterline(fine_center_line);
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit concerned that the function start to exceed what it was originally designed for.
Is it necessary to move the customized center line to waypoints at runtime?

/**
 * @brief  Apply a patch for centerline because the original implementation
 * doesn't have enough quality
 */

} else {
if (!lanelet_obj.hasCustomCenterline()) {
const auto fine_center_line = generateFineCenterline(lanelet_obj, resolution);
lanelet_obj.setCenterline(fine_center_line);
}
}
}
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
50 changes: 48 additions & 2 deletions tmp/lanelet2_extension/test/src/test_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class TestSuite : public ::testing::Test // NOLINT for gtest
merging_lanelet.attributes()[lanelet::AttributeName::Subtype] =
lanelet::AttributeValueString::Road;

// create sample lanelets
Point3d cp1 = Point3d(getId(), 0.5, 0., 0.);
Point3d cp2 = Point3d(getId(), 0.5, 0.5, 0.);
Point3d cp3 = Point3d(getId(), 0.5, 1., 0.);

LineString3d ls_centerline(getId(), {cp1, cp2, cp3});
road_lanelet.setCenterline(ls_centerline);

sample_map_ptr->add(road_lanelet);
sample_map_ptr->add(next_lanelet);
sample_map_ptr->add(next_lanelet2);
Expand All @@ -104,12 +112,50 @@ class TestSuite : public ::testing::Test // NOLINT for gtest
private:
};

TEST_F(TestSuite, OverwriteLaneletsCenterline) // NOLINT for gtest
TEST_F(TestSuite, OverwriteLaneletsCenterlineWithWaypoints) // NOLINT for gtest
{
double resolution = 5.0;
bool force_overwrite = false;
bool use_waypoints = true;

// memorize the original information of the centerline
std::unordered_map<lanelet::Id, lanelet::Id> lanelet_centerline_map{};
for (const auto & lanelet : sample_map_ptr->laneletLayer) {
if (lanelet.hasCustomCenterline()) {
lanelet_centerline_map.insert({lanelet.id(), lanelet.centerline().id()});
}
}

// convert centerline to waypoints
lanelet::utils::overwriteLaneletsCenterline(
sample_map_ptr, resolution, use_waypoints, force_overwrite);

for (const auto & lanelet : sample_map_ptr->laneletLayer) {
if (lanelet_centerline_map.find(lanelet.id()) != lanelet_centerline_map.end()) {
// check if the lanelet has waypoints.
ASSERT_TRUE(lanelet.hasAttribute("waypoints")) << "The lanelet does not have a waypoints.";
// check if the waypoints points to the linestring of the centerline.
ASSERT_TRUE(
lanelet.attribute("waypoints").asId().value() == lanelet_centerline_map.at(lanelet.id()))
<< "The waypoint's ID is invalid.";
}
}

// check if all the lanelets have a centerline
for (const auto & lanelet : sample_map_ptr->laneletLayer) {
ASSERT_TRUE(lanelet.hasCustomCenterline()) << "failed to calculate fine centerline";
}
}

TEST_F(TestSuite, OverwriteLaneletsCenterlineWithoutWaypoints) // NOLINT for gtest
{
double resolution = 5.0;
bool force_overwrite = false;
lanelet::utils::overwriteLaneletsCenterline(sample_map_ptr, resolution, force_overwrite);
bool use_waypoints = false;
lanelet::utils::overwriteLaneletsCenterline(
sample_map_ptr, resolution, use_waypoints, force_overwrite);

// check if all the lanelets have a centerline
for (const auto & lanelet : sample_map_ptr->laneletLayer) {
ASSERT_TRUE(lanelet.hasCustomCenterline()) << "failed to calculate fine centerline";
}
Expand Down
2 changes: 1 addition & 1 deletion tmp/lanelet2_extension_python/src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(
BOOST_PYTHON_FUNCTION_OVERLOADS(
getLeftBoundWithOffset_overload, lanelet::utils::getLeftBoundWithOffset, 2, 3)
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
BOOST_PYTHON_FUNCTION_OVERLOADS(
overwriteLaneletsCenterline_overload, lanelet::utils::overwriteLaneletsCenterline, 1, 3)
overwriteLaneletsCenterline_overload, lanelet::utils::overwriteLaneletsCenterline, 3, 4)
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
BOOST_PYTHON_FUNCTION_OVERLOADS(isInLanelet_overload, ::isInLanelet, 2, 3)
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved
takayuki5168 marked this conversation as resolved.
Show resolved Hide resolved

/// query.cpp
Expand Down
Loading