Skip to content

Commit

Permalink
refactor(avoidance_by_lane_change): rework execution condition
Browse files Browse the repository at this point in the history
Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed Dec 4, 2023
1 parent 887446f commit cb64a6a
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,37 @@ bool AvoidanceByLaneChange::specialRequiredCheck() const
return false;
}

const auto & target_objects = avoidance_data_.target_objects;
if(target_objects.empty()){
return false;
}

const auto & object_parameters = avoidance_parameters_->object_parameters;
const auto is_more_than_threshold =
std::any_of(object_parameters.begin(), object_parameters.end(), [&](const auto & p) {
const auto & objects = avoidance_data_.target_objects;

const size_t num = std::count_if(objects.begin(), objects.end(), [&p](const auto & object) {
const auto target_class =
utils::getHighestProbLabel(object.object.classification) == p.first;
return target_class && object.avoid_required;
});

return num >= p.second.execute_num;
});
const auto is_more_than_threshold = [&](const auto & p) {

const auto is_type_to_avoid = [&p](const auto & object) {
const auto target_class = utils::getHighestProbLabel(object.object.classification) == p.first;
return target_class && object.avoid_required;
};

if (!is_more_than_threshold) {
const auto num_of_objects = std::count_if(target_objects.begin(), target_objects.end(), is_type_to_avoid);

return num_of_objects >= 2;
};

if (!std::any_of(object_parameters.begin(), object_parameters.end(), is_more_than_threshold)) {
return false;
}

const auto & front_object = data.target_objects.front();
const auto shift_intervals =
getRouteHandler()->getLateralIntervalsToPreferredLane(status_.current_lanes.back());
const auto common_param = getCommonParam();
const auto minimum_lane_change_length = utils::calcMinimumLaneChangeLength(
common_param, shift_intervals, common_param.backward_length_buffer_for_end_of_lane);

const auto THRESHOLD = avoidance_parameters_->execute_object_longitudinal_margin;
if (front_object.longitudinal < THRESHOLD) {
if (front_object.longitudinal < minimum_lane_change_length) {
return false;
}

Expand All @@ -77,11 +86,7 @@ bool AvoidanceByLaneChange::specialRequiredCheck() const
avoidance_parameters_->execute_only_when_lane_change_finish_before_object;
const auto not_enough_distance = front_object.longitudinal < to_lc_end;

if (execute_only_when_lane_change_finish_before_object && not_enough_distance) {
return false;
}

return true;
return !(execute_only_when_lane_change_finish_before_object && not_enough_distance);
}

bool AvoidanceByLaneChange::specialExpiredCheck() const
Expand Down

0 comments on commit cb64a6a

Please sign in to comment.