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

fix(avoidance): cherry pick #1085

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ AvoidancePlanningData AvoidanceByLaneChange::calcAvoidancePlanningData(
std::for_each(
data.current_lanelets.begin(), data.current_lanelets.end(), [&](const auto & lanelet) {
data.drivable_lanes.push_back(utils::avoidance::generateExpandDrivableLanes(
lanelet, planner_data_, avoidance_parameters_));
lanelet, planner_data_, avoidance_parameters_, false));
});

// calc drivable bound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ std::pair<PredictedObjects, PredictedObjects> separateObjectsByPath(

DrivableLanes generateExpandDrivableLanes(
const lanelet::ConstLanelet & lanelet, const std::shared_ptr<const PlannerData> & planner_data,
const std::shared_ptr<AvoidanceParameters> & parameters);
const std::shared_ptr<AvoidanceParameters> & parameters, const bool in_avoidance_maneuver);

double calcDistanceToReturnDeadLine(
const lanelet::ConstLanelets & lanelets, const PathWithLaneId & path,
Expand Down
9 changes: 6 additions & 3 deletions planning/behavior_path_avoidance_module/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ void AvoidanceModule::fillFundamentalData(AvoidancePlanningData & data, DebugDat
utils::avoidance::getExtendLanes(data.current_lanelets, getEgoPose(), planner_data_);

// expand drivable lanes
const auto has_shift_point = !path_shifter_.getShiftLines().empty();
const auto in_avoidance_maneuver = has_shift_point || helper_->isShifted();
std::for_each(
data.current_lanelets.begin(), data.current_lanelets.end(), [&](const auto & lanelet) {
data.drivable_lanes.push_back(
utils::avoidance::generateExpandDrivableLanes(lanelet, planner_data_, parameters_));
data.drivable_lanes.push_back(utils::avoidance::generateExpandDrivableLanes(
lanelet, planner_data_, parameters_, in_avoidance_maneuver));
});

// calc drivable bound
Expand Down Expand Up @@ -1388,7 +1390,8 @@ void AvoidanceModule::insertReturnDeadLine(
shifted_path.path.points, getEgoPosition(), shifted_path.path.points.size() - 1);
const auto buffer = std::max(0.0, to_shifted_path_end - to_reference_path_end);

const auto min_return_distance = helper_->getMinAvoidanceDistance(shift_length);
const auto min_return_distance =
helper_->getMinAvoidanceDistance(shift_length) + helper_->getMinimumPrepareDistance();
const auto to_stop_line = data.to_return_point - min_return_distance - buffer;

// If we don't need to consider deceleration constraints, insert a deceleration point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,12 +1101,14 @@ AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
const double variable_prepare_distance =
std::max(nominal_prepare_distance - last_sl_distance, 0.0);

double prepare_distance_scaled = std::max(nominal_prepare_distance, last_sl_distance);
double prepare_distance_scaled =
std::clamp(nominal_prepare_distance, helper_->getMinimumPrepareDistance(), last_sl_distance);
double avoid_distance_scaled = nominal_avoid_distance;
if (remaining_distance < prepare_distance_scaled + avoid_distance_scaled) {
const auto scale = (remaining_distance - last_sl_distance) /
std::max(nominal_avoid_distance + variable_prepare_distance, 0.1);
prepare_distance_scaled = last_sl_distance + scale * nominal_prepare_distance;
prepare_distance_scaled = std::max(
helper_->getMinimumPrepareDistance(), last_sl_distance + scale * nominal_prepare_distance);
avoid_distance_scaled *= scale;
}

Expand Down Expand Up @@ -1219,7 +1221,7 @@ AvoidLineArray ShiftLineGenerator::findNewShiftLine(
const auto & candidate = shift_lines.at(i);

// prevent sudden steering.
if (candidate.start_longitudinal < helper_->getMinimumPrepareDistance()) {
if (candidate.start_longitudinal + 1e-3 < helper_->getMinimumPrepareDistance()) {
break;
}

Expand Down
12 changes: 11 additions & 1 deletion planning/behavior_path_avoidance_module/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ std::pair<PredictedObjects, PredictedObjects> separateObjectsByPath(

DrivableLanes generateExpandDrivableLanes(
const lanelet::ConstLanelet & lanelet, const std::shared_ptr<const PlannerData> & planner_data,
const std::shared_ptr<AvoidanceParameters> & parameters)
const std::shared_ptr<AvoidanceParameters> & parameters, const bool in_avoidance_maneuver)
{
const auto & route_handler = planner_data->route_handler;

Expand All @@ -1967,6 +1967,11 @@ DrivableLanes generateExpandDrivableLanes(

// 1. get left/right side lanes
const auto update_left_lanelets = [&](const lanelet::ConstLanelet & target_lane) {
const auto next_lanes = route_handler->getNextLanelets(target_lane);
const auto is_stop_signal = utils::traffic_light::isTrafficSignalStop(next_lanes, planner_data);
if (is_stop_signal && !in_avoidance_maneuver) {
return;
}
const auto all_left_lanelets = route_handler->getAllLeftSharedLinestringLanelets(
target_lane, parameters->use_opposite_lane, true);
if (!all_left_lanelets.empty()) {
Expand All @@ -1977,6 +1982,11 @@ DrivableLanes generateExpandDrivableLanes(
}
};
const auto update_right_lanelets = [&](const lanelet::ConstLanelet & target_lane) {
const auto next_lanes = route_handler->getNextLanelets(target_lane);
const auto is_stop_signal = utils::traffic_light::isTrafficSignalStop(next_lanes, planner_data);
if (is_stop_signal && !in_avoidance_maneuver) {
return;
}
const auto all_right_lanelets = route_handler->getAllRightSharedLinestringLanelets(
target_lane, parameters->use_opposite_lane, true);
if (!all_right_lanelets.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ bool isStoppedAtRedTrafficLightWithinDistance(
const lanelet::ConstLanelets & lanelets, const PathWithLaneId & path,
const std::shared_ptr<const PlannerData> & planner_data,
const double distance_threshold = std::numeric_limits<double>::infinity());

/**
* @brief Determines if a traffic signal indicates a stop for the given lanelet.
*
* Evaluates the current state of the traffic light, considering if it's green or unknown,
* which would not necessitate a stop. Then, it checks the turn direction attribute of the lanelet
* against the traffic light's arrow shapes to determine whether a vehicle must stop or if it can
* proceed based on allowed turn directions.
*
* @param lanelet The lanelet to check for a stop signal at its traffic light.
* @param planner_data Shared pointer to the planner data containing vehicle state information.
* @return True if the traffic signal indicates a stop is required, false otherwise.
*/
bool isTrafficSignalStop(
const lanelet::ConstLanelets & lanelets, const std::shared_ptr<const PlannerData> & planner_data);
} // namespace behavior_path_planner::utils::traffic_light

#endif // BEHAVIOR_PATH_PLANNER_COMMON__UTILS__TRAFFIC_LIGHT_UTILS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ geometry_msgs::msg::Point calcLongitudinalOffsetGoalPoint(

return offset_point ? offset_point.value() : points.at(nearest_segment_idx + 1);
}

std::vector<lanelet::ConstPoint3d> extractBoundFromPolygon(
const lanelet::ConstPolygon3d & polygon, const size_t start_idx, const size_t end_idx,
const bool clockwise)
{
std::vector<lanelet::ConstPoint3d> ret{};
for (size_t i = start_idx; i != end_idx; i = clockwise ? i + 1 : i - 1) {
ret.push_back(polygon[i]);

if (i + 1 == polygon.size() && clockwise) {
if (end_idx == 0) {
ret.push_back(polygon[end_idx]);
return ret;
}
i = 0;
ret.push_back(polygon[i]);
continue;
}

if (i == 0 && !clockwise) {
if (end_idx == polygon.size() - 1) {
ret.push_back(polygon[end_idx]);
return ret;
}
i = polygon.size() - 1;
ret.push_back(polygon[i]);
continue;
}
}

ret.push_back(polygon[end_idx]);

return ret;
}
} // namespace

namespace behavior_path_planner::utils::drivable_area_processing
Expand Down Expand Up @@ -1261,36 +1295,6 @@ std::vector<lanelet::ConstPoint3d> getBoundWithIntersectionAreas(
const std::shared_ptr<RouteHandler> & route_handler,
const std::vector<DrivableLanes> & drivable_lanes, const bool is_left)
{
const auto extract_bound_from_polygon =
[](const auto & polygon, const auto start_idx, const auto end_idx, const auto clockwise) {
std::vector<lanelet::ConstPoint3d> ret{};
for (size_t i = start_idx; i != end_idx; i = clockwise ? i + 1 : i - 1) {
ret.push_back(polygon[i]);

if (i + 1 == polygon.size() && clockwise) {
if (end_idx == 0) {
ret.push_back(polygon[end_idx]);
return ret;
}
i = 0;
continue;
}

if (i == 0 && !clockwise) {
if (end_idx == polygon.size() - 1) {
ret.push_back(polygon[end_idx]);
return ret;
}
i = polygon.size() - 1;
continue;
}
}

ret.push_back(polygon[end_idx]);

return ret;
};

std::vector<lanelet::ConstPoint3d> expanded_bound = original_bound;

// expand drivable area by using intersection area.
Expand Down Expand Up @@ -1336,7 +1340,7 @@ std::vector<lanelet::ConstPoint3d> getBoundWithIntersectionAreas(
const size_t end_idx = std::distance(polygon.begin(), intersection_bound_itr_last);

intersection_bound =
extract_bound_from_polygon(polygon, start_idx, end_idx, is_clockwise_iteration);
extractBoundFromPolygon(polygon, start_idx, end_idx, is_clockwise_iteration);
}

// Step2. check shared bound point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,24 @@ bool isStoppedAtRedTrafficLightWithinDistance(
return (distance_to_red_traffic_light < distance_threshold);
}

bool isTrafficSignalStop(
const lanelet::ConstLanelets & lanelets, const std::shared_ptr<const PlannerData> & planner_data)
{
for (const auto & lanelet : lanelets) {
for (const auto & element : lanelet.regulatoryElementsAs<TrafficLight>()) {
const auto traffic_signal_stamped = planner_data->getTrafficSignal(element->id());
if (!traffic_signal_stamped.has_value()) {
continue;
}

if (traffic_light_utils::isTrafficSignalStop(
lanelet, traffic_signal_stamped.value().signal)) {
return true;
}
}
}

return false;
}

} // namespace behavior_path_planner::utils::traffic_light
Loading