@@ -239,10 +239,18 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
239
239
240
240
const auto is_forward_object = [](const auto & object) { return object.longitudinal > 0.0 ; };
241
241
242
+ const auto is_on_path = [this ](const auto & object) {
243
+ const auto [overhang, point] = object.overhang_points .front ();
244
+ return std::abs (overhang) < 0.5 * data_->parameters .vehicle_width ;
245
+ };
246
+
242
247
const auto is_valid_shift_line = [](const auto & s) {
243
248
return s.start_longitudinal > 0.0 && s.start_longitudinal < s.end_longitudinal ;
244
249
};
245
250
251
+ ObjectDataArray unavoidable_objects;
252
+
253
+ // target objects are sorted by longitudinal distance.
246
254
AvoidOutlines outlines;
247
255
for (auto & o : data.target_objects ) {
248
256
if (!o.avoid_margin .has_value ()) {
@@ -253,36 +261,48 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
253
261
} else {
254
262
o.info = ObjectInfo::INSUFFICIENT_DRIVABLE_SPACE;
255
263
}
256
- if (o.avoid_required && is_forward_object (o)) {
264
+ if (o.avoid_required && is_forward_object (o) && is_on_path (o) ) {
257
265
break ;
258
266
} else {
267
+ unavoidable_objects.push_back (o);
259
268
continue ;
260
269
}
261
270
}
262
271
263
- const auto is_object_on_right = utils::static_obstacle_avoidance::isOnRight (o);
264
272
const auto desire_shift_length =
265
- helper_->getShiftLength (o, is_object_on_right, o.avoid_margin .value ());
266
- if (utils::static_obstacle_avoidance::isSameDirectionShift (
267
- is_object_on_right, desire_shift_length)) {
273
+ helper_->getShiftLength (o, isOnRight (o), o.avoid_margin .value ());
274
+ if (utils::static_obstacle_avoidance::isSameDirectionShift (isOnRight (o), desire_shift_length)) {
268
275
o.info = ObjectInfo::SAME_DIRECTION_SHIFT;
269
- if (o.avoid_required && is_forward_object (o)) {
276
+ if (o.avoid_required && is_forward_object (o) && is_on_path (o) ) {
270
277
break ;
271
278
} else {
279
+ unavoidable_objects.push_back (o);
272
280
continue ;
273
281
}
274
282
}
275
283
276
284
// calculate feasible shift length based on behavior policy
277
285
const auto feasible_shift_profile = get_shift_profile (o, desire_shift_length);
278
286
if (!feasible_shift_profile.has_value ()) {
279
- if (o.avoid_required && is_forward_object (o)) {
287
+ if (o.avoid_required && is_forward_object (o) && is_on_path (o) ) {
280
288
break ;
281
289
} else {
290
+ unavoidable_objects.push_back (o);
282
291
continue ;
283
292
}
284
293
}
285
294
295
+ // If there is an object that cannot be avoided, this module only avoids object on the same side
296
+ // as unavoidable object.
297
+ if (!unavoidable_objects.empty ()) {
298
+ if (isOnRight (unavoidable_objects.front ()) && !isOnRight (o)) {
299
+ break ;
300
+ }
301
+ if (!isOnRight (unavoidable_objects.front ()) && isOnRight (o)) {
302
+ break ;
303
+ }
304
+ }
305
+
286
306
// use absolute dist for return-to-center, relative dist from current for avoiding.
287
307
const auto feasible_return_distance =
288
308
helper_->getMaxAvoidanceDistance (feasible_shift_profile.value ().first );
0 commit comments