Skip to content

Commit

Permalink
Merge pull request autowarefoundation#903 from satoshi-ota/hotfix/avo…
Browse files Browse the repository at this point in the history
…idance

hotfix(avoidance): cherry pick bug fix commits
  • Loading branch information
tkimura4 authored Oct 3, 2023
2 parents fa61805 + 7957ed3 commit 3ab1243
Showing 1 changed file with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2127,26 +2127,29 @@ void AvoidanceModule::generateExtendedDrivableArea(BehaviorModuleOutput & output

PathWithLaneId AvoidanceModule::extendBackwardLength(const PathWithLaneId & original_path) const
{
// special for avoidance: take behind distance upt ot shift-start-point if it exist.
const auto previous_path = helper_.getPreviousReferencePath();

const auto longest_dist_to_shift_point = [&]() {
double max_dist = 0.0;
for (const auto & pnt : path_shifter_.getShiftLines()) {
max_dist = std::max(max_dist, calcDistance2d(getEgoPose(), pnt.start));
max_dist = std::max(
max_dist, calcSignedArcLength(previous_path.points, pnt.start.position, getEgoPosition()));
}
for (const auto & sp : registered_raw_shift_lines_) {
max_dist = std::max(max_dist, calcDistance2d(getEgoPose(), sp.start));
max_dist = std::max(
max_dist, calcSignedArcLength(previous_path.points, sp.start.position, getEgoPosition()));
}
return max_dist;
}();

const auto extra_margin = 10.0; // Since distance does not consider arclength, but just line.
const auto backward_length = std::max(
planner_data_->parameters.backward_path_length, longest_dist_to_shift_point + extra_margin);
const auto previous_path = helper_.getPreviousReferencePath();

const size_t orig_ego_idx = planner_data_->findEgoIndex(original_path.points);
const size_t prev_ego_idx =
findNearestSegmentIndex(previous_path.points, getPoint(original_path.points.at(orig_ego_idx)));
const size_t prev_ego_idx = motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
previous_path.points, getPose(original_path.points.at(orig_ego_idx)),
std::numeric_limits<double>::max(), planner_data_->parameters.ego_nearest_yaw_threshold);

size_t clip_idx = 0;
for (size_t i = 0; i < prev_ego_idx; ++i) {
Expand Down Expand Up @@ -2289,37 +2292,35 @@ CandidateOutput AvoidanceModule::planCandidate() const

auto shifted_path = data.candidate_path;

if (!data.safe_new_sl.empty()) { // clip from shift start index for visualize
utils::clipPathLength(
shifted_path.path, data.safe_new_sl.front().start_idx, std::numeric_limits<double>::max(),
0.0);
if (data.safe_new_sl.empty()) {
const size_t ego_idx = planner_data_->findEgoIndex(shifted_path.path.points);
utils::clipPathLength(shifted_path.path, ego_idx, planner_data_->parameters);

const auto sl = helper_.getMainShiftLine(data.safe_new_sl);
const auto sl_front = data.safe_new_sl.front();
const auto sl_back = data.safe_new_sl.back();
output.path_candidate = shifted_path.path;
return output;
}

output.lateral_shift = helper_.getRelativeShiftToPath(sl);
output.start_distance_to_path_change = sl_front.start_longitudinal;
output.finish_distance_to_path_change = sl_back.end_longitudinal;
const auto sl = helper_.getMainShiftLine(data.safe_new_sl);
const auto sl_front = data.safe_new_sl.front();
const auto sl_back = data.safe_new_sl.back();

const uint16_t steering_factor_direction = std::invoke([&output]() {
if (output.lateral_shift > 0.0) {
return SteeringFactor::LEFT;
}
return SteeringFactor::RIGHT;
});
steering_factor_interface_ptr_->updateSteeringFactor(
{sl_front.start, sl_back.end},
{output.start_distance_to_path_change, output.finish_distance_to_path_change},
SteeringFactor::AVOIDANCE_PATH_CHANGE, steering_factor_direction, SteeringFactor::APPROACHING,
"");
}
utils::clipPathLength(
shifted_path.path, sl_front.start_idx, std::numeric_limits<double>::max(), 0.0);

const size_t ego_idx = planner_data_->findEgoIndex(shifted_path.path.points);
utils::clipPathLength(shifted_path.path, ego_idx, planner_data_->parameters);
output.lateral_shift = helper_.getRelativeShiftToPath(sl);
output.start_distance_to_path_change = sl_front.start_longitudinal;
output.finish_distance_to_path_change = sl_back.end_longitudinal;

output.path_candidate = shifted_path.path;
const uint16_t steering_factor_direction = std::invoke([&output]() {
return output.lateral_shift > 0.0 ? SteeringFactor::LEFT : SteeringFactor::RIGHT;
});
steering_factor_interface_ptr_->updateSteeringFactor(
{sl_front.start, sl_back.end},
{output.start_distance_to_path_change, output.finish_distance_to_path_change},
SteeringFactor::AVOIDANCE_PATH_CHANGE, steering_factor_direction, SteeringFactor::APPROACHING,
"");

output.path_candidate = shifted_path.path;
return output;
}

Expand Down

0 comments on commit 3ab1243

Please sign in to comment.