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

refactor(avoidance_module): change implementation to lambda #486

Original file line number Diff line number Diff line change
Expand Up @@ -1675,35 +1675,20 @@ void AvoidanceModule::generateExtendedDrivableArea(ShiftedPath * shifted_path) c
{
// 0. Extend to right/left of objects
for (const auto & obstacle : avoidance_data_.objects) {
lanelet::ConstLanelets search_lanelets;
auto object_lanelet = obstacle.overhang_lanelet;
constexpr bool get_right = true;
constexpr bool get_left = true;
const bool include_opposite = parameters_.enable_avoidance_over_opposite_direction;
if (isOnRight(obstacle)) {
auto lanelet_at_left = route_handler->getLeftLanelet(object_lanelet);
while (lanelet_at_left) {
extended_lanelets.push_back(lanelet_at_left.get());
lanelet_at_left = route_handler->getLeftLanelet(lanelet_at_left.get());
}
if (lanelet_at_left) {
auto lanelet_at_right =
planner_data_->route_handler->getRightLanelet(lanelet_at_left.get());
while (lanelet_at_right) {
extended_lanelets.push_back(lanelet_at_right.get());
lanelet_at_right = route_handler->getRightLanelet(lanelet_at_right.get());
}
}
search_lanelets = route_handler->getAllSharedLineStringLanelets(
object_lanelet, !get_right, get_left, include_opposite);
} else {
auto lanelet_at_right = route_handler->getRightLanelet(object_lanelet);
while (lanelet_at_right) {
extended_lanelets.push_back(lanelet_at_right.get());
lanelet_at_right = route_handler->getRightLanelet(lanelet_at_right.get());
}
if (lanelet_at_right) {
auto lanelet_at_left = route_handler->getLeftLanelet(lanelet_at_right.get());
while (lanelet_at_left) {
extended_lanelets.push_back(lanelet_at_left.get());
lanelet_at_left = route_handler->getLeftLanelet(lanelet_at_left.get());
}
}
search_lanelets = route_handler->getAllSharedLineStringLanelets(
object_lanelet, get_right, !get_left, include_opposite);
}
extended_lanelets.insert(
extended_lanelets.end(), search_lanelets.begin(), search_lanelets.end());
}
}

Expand Down
30 changes: 30 additions & 0 deletions planning/route_handler/include/route_handler/route_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ class RouteHandler
*/
lanelet::Lanelets getLeftOppositeLanelets(const lanelet::ConstLanelet & lanelet) const;

/**
* @brief Searches and return all lanelet on the left that shares same linestring
* @param the lanelet of interest
* @param (optional) flag to include the lane with opposite direction
* @return vector of lanelet that is connected via share linestring
*/
lanelet::ConstLanelets getAllLeftSharedLinestringLanelets(
const lanelet::ConstLanelet & lane, const bool & include_opposite) const noexcept;

/**
* @brief Searches and return all lanelet on the right that shares same linestring
* @param the lanelet of interest
* @param (optional) flag to include the lane with opposite direction
* @return vector of lanelet that is connected via share linestring
*/
lanelet::ConstLanelets getAllRightSharedLinestringLanelets(
const lanelet::ConstLanelet & lane, const bool & include_opposite) const noexcept;

/**
* @brief Searches and return all lanelet (left and right) that shares same linestring
* @param the lanelet of interest
* @param (optional) flag to search only right side
* @param (optional) flag to search only left side
* @param (optional) flag to include the lane with opposite direction
* @return vector of lanelet that is connected via share linestring
*/
lanelet::ConstLanelets getAllSharedLineStringLanelets(
const lanelet::ConstLanelet & current_lane, bool is_right = true, bool is_left = true,
bool is_opposite = true) const noexcept;

/**
* @brief Searches the furthest linestring to the right side of the lanelet
* Only lanelet with same direction is considered
Expand Down
67 changes: 67 additions & 0 deletions planning/route_handler/src/route_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,73 @@ lanelet::Lanelets RouteHandler::getRightOppositeLanelets(
return lanelet_map_ptr_->laneletLayer.findUsages(lanelet.rightBound().invert());
}

lanelet::ConstLanelets RouteHandler::getAllLeftSharedLinestringLanelets(
const lanelet::ConstLanelet & lane, const bool & include_opposite) const noexcept
{
lanelet::ConstLanelets shared;
taikitanaka3 marked this conversation as resolved.
Show resolved Hide resolved
auto lanelet_at_left = getLeftLanelet(lane);
auto lanelet_at_left_opposite = getLeftOppositeLanelets(lane);
while (lanelet_at_left) {
shared.push_back(lanelet_at_left.get());
lanelet_at_left = getLeftLanelet(lanelet_at_left.get());
lanelet_at_left_opposite = getLeftOppositeLanelets(lanelet_at_left.get());
}

if (!lanelet_at_left_opposite.empty() && include_opposite) {
shared.push_back(lanelet_at_left_opposite.front());
auto lanelet_at_right = getRightLanelet(lanelet_at_left_opposite.front());
while (lanelet_at_right) {
shared.push_back(lanelet_at_right.get());
lanelet_at_right = getRightLanelet(lanelet_at_right.get());
}
}
return shared;
}

lanelet::ConstLanelets RouteHandler::getAllRightSharedLinestringLanelets(
const lanelet::ConstLanelet & lane, const bool & include_opposite) const noexcept
{
lanelet::ConstLanelets shared;
auto lanelet_at_right = getRightLanelet(lane);
auto lanelet_at_right_opposite = getRightOppositeLanelets(lane);
while (lanelet_at_right) {
shared.push_back(lanelet_at_right.get());
lanelet_at_right = getRightLanelet(lanelet_at_right.get());
lanelet_at_right_opposite = getRightOppositeLanelets(lanelet_at_right.get());
}

if (!lanelet_at_right_opposite.empty() && include_opposite) {
shared.push_back(lanelet_at_right_opposite.front());
auto lanelet_at_left = getLeftLanelet(lanelet_at_right_opposite.front());
while (lanelet_at_left) {
shared.push_back(lanelet_at_left.get());
lanelet_at_left = getLeftLanelet(lanelet_at_left.get());
}
}
return shared;
}

lanelet::ConstLanelets RouteHandler::getAllSharedLineStringLanelets(
const lanelet::ConstLanelet & current_lane, bool is_right, bool is_left,
taikitanaka3 marked this conversation as resolved.
Show resolved Hide resolved
bool is_opposite) const noexcept
{
lanelet::ConstLanelets shared{current_lane};

if (is_right) {
const lanelet::ConstLanelets all_right_lanelets =
getAllRightSharedLinestringLanelets(current_lane, is_opposite);
shared.insert(shared.end(), all_right_lanelets.begin(), all_right_lanelets.end());
}

if (is_left) {
const lanelet::ConstLanelets all_left_lanelets =
getAllLeftSharedLinestringLanelets(current_lane, is_opposite);
shared.insert(shared.end(), all_left_lanelets.begin(), all_left_lanelets.end());
}

return shared;
}

lanelet::Lanelets RouteHandler::getLeftOppositeLanelets(const lanelet::ConstLanelet & lanelet) const
{
return lanelet_map_ptr_->laneletLayer.findUsages(lanelet.leftBound().invert());
Expand Down