@@ -250,16 +250,37 @@ void pushUniqueVector(T & base_vector, const T & additional_vector)
250
250
base_vector.insert (base_vector.end (), additional_vector.begin (), additional_vector.end ());
251
251
}
252
252
253
+ bool isAvoidShift (
254
+ const double start_shift_length, const double end_shift_length, const double threshold)
255
+ {
256
+ return std::abs (start_shift_length) < threshold && std::abs (end_shift_length) > threshold;
257
+ }
258
+
259
+ bool isReturnShift (
260
+ const double start_shift_length, const double end_shift_length, const double threshold)
261
+ {
262
+ return std::abs (start_shift_length) > threshold && std::abs (end_shift_length) < threshold;
263
+ }
264
+
265
+ bool isLeftMiddleShift (
266
+ const double start_shift_length, const double end_shift_length, const double threshold)
267
+ {
268
+ return start_shift_length > threshold && end_shift_length > threshold;
269
+ }
270
+
271
+ bool isRightMiddleShift (
272
+ const double start_shift_length, const double end_shift_length, const double threshold)
273
+ {
274
+ return start_shift_length < threshold && end_shift_length < threshold;
275
+ }
276
+
253
277
bool existShiftSideLane (
254
278
const double start_shift_length, const double end_shift_length, const bool no_left_lanes,
255
- const bool no_right_lanes)
279
+ const bool no_right_lanes, const double threshold )
256
280
{
257
- constexpr double THRESHOLD = 0.1 ;
258
281
const auto relative_shift_length = end_shift_length - start_shift_length;
259
282
260
- const auto avoid_shift =
261
- std::abs (start_shift_length) < THRESHOLD && std::abs (end_shift_length) > THRESHOLD;
262
- if (avoid_shift) {
283
+ if (isAvoidShift (start_shift_length, end_shift_length, threshold)) {
263
284
// Left avoid. But there is no adjacent lane. No need blinker.
264
285
if (relative_shift_length > 0.0 && no_left_lanes) {
265
286
return false ;
@@ -271,9 +292,7 @@ bool existShiftSideLane(
271
292
}
272
293
}
273
294
274
- const auto return_shift =
275
- std::abs (start_shift_length) > THRESHOLD && std::abs (end_shift_length) < THRESHOLD;
276
- if (return_shift) {
295
+ if (isReturnShift (start_shift_length, end_shift_length, threshold)) {
277
296
// Right return. But there is no adjacent lane. No need blinker.
278
297
if (relative_shift_length > 0.0 && no_right_lanes) {
279
298
return false ;
@@ -285,8 +304,7 @@ bool existShiftSideLane(
285
304
}
286
305
}
287
306
288
- const auto left_middle_shift = start_shift_length > THRESHOLD && end_shift_length > THRESHOLD;
289
- if (left_middle_shift) {
307
+ if (isLeftMiddleShift (start_shift_length, end_shift_length, threshold)) {
290
308
// Left avoid. But there is no adjacent lane. No need blinker.
291
309
if (relative_shift_length > 0.0 && no_left_lanes) {
292
310
return false ;
@@ -298,8 +316,7 @@ bool existShiftSideLane(
298
316
}
299
317
}
300
318
301
- const auto right_middle_shift = start_shift_length < THRESHOLD && end_shift_length < THRESHOLD;
302
- if (right_middle_shift) {
319
+ if (isRightMiddleShift (start_shift_length, end_shift_length, threshold)) {
303
320
// Right avoid. But there is no adjacent lane. No need blinker.
304
321
if (relative_shift_length < 0.0 && no_right_lanes) {
305
322
return false ;
@@ -314,6 +331,23 @@ bool existShiftSideLane(
314
331
return true ;
315
332
}
316
333
334
+ bool isNearEndOfShift (
335
+ const double start_shift_length, const double end_shift_length, const Point & ego_pos,
336
+ const lanelet::ConstLanelets & original_lanes, const double threshold)
337
+ {
338
+ using boost::geometry::within;
339
+ using lanelet::utils::to2D;
340
+ using lanelet::utils::conversion::toLaneletPoint;
341
+
342
+ if (!isReturnShift (start_shift_length, end_shift_length, threshold)) {
343
+ return false ;
344
+ }
345
+
346
+ return std::any_of (original_lanes.begin (), original_lanes.end (), [&ego_pos](const auto & lane) {
347
+ return within (to2D (toLaneletPoint (ego_pos)), lane.polygon2d ().basicPolygon ());
348
+ });
349
+ }
350
+
317
351
bool straddleRoadBound (
318
352
const ShiftedPath & path, const ShiftLine & shift_line, const lanelet::ConstLanelets & lanes,
319
353
const vehicle_info_util::VehicleInfo & vehicle_info)
@@ -2323,7 +2357,7 @@ double calcDistanceToReturnDeadLine(
2323
2357
return distance_to_return_dead_line;
2324
2358
}
2325
2359
2326
- TurnSignalInfo calcTurnSignalInfo (
2360
+ std::pair< TurnSignalInfo, bool > calcTurnSignalInfo (
2327
2361
const ShiftedPath & path, const ShiftLine & shift_line, const double current_shift_length,
2328
2362
const AvoidancePlanningData & data, const std::shared_ptr<const PlannerData> & planner_data)
2329
2363
{
@@ -2335,22 +2369,22 @@ TurnSignalInfo calcTurnSignalInfo(
2335
2369
2336
2370
if (shift_line.start_idx + 1 > path.shift_length .size ()) {
2337
2371
RCLCPP_WARN (rclcpp::get_logger (__func__), " index inconsistency." );
2338
- return {} ;
2372
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2339
2373
}
2340
2374
2341
2375
if (shift_line.start_idx + 1 > path.path .points .size ()) {
2342
2376
RCLCPP_WARN (rclcpp::get_logger (__func__), " index inconsistency." );
2343
- return {} ;
2377
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2344
2378
}
2345
2379
2346
2380
if (shift_line.end_idx + 1 > path.shift_length .size ()) {
2347
2381
RCLCPP_WARN (rclcpp::get_logger (__func__), " index inconsistency." );
2348
- return {} ;
2382
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2349
2383
}
2350
2384
2351
2385
if (shift_line.end_idx + 1 > path.path .points .size ()) {
2352
2386
RCLCPP_WARN (rclcpp::get_logger (__func__), " index inconsistency." );
2353
- return {} ;
2387
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2354
2388
}
2355
2389
2356
2390
const auto start_shift_length = path.shift_length .at (shift_line.start_idx );
@@ -2359,12 +2393,12 @@ TurnSignalInfo calcTurnSignalInfo(
2359
2393
2360
2394
// If shift length is shorter than the threshold, it does not need to turn on blinkers
2361
2395
if (std::fabs (relative_shift_length) < p.turn_signal_shift_length_threshold ) {
2362
- return {} ;
2396
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2363
2397
}
2364
2398
2365
2399
// If the vehicle does not shift anymore, we turn off the blinker
2366
2400
if (std::fabs (path.shift_length .at (shift_line.end_idx ) - current_shift_length) < THRESHOLD) {
2367
- return {} ;
2401
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2368
2402
}
2369
2403
2370
2404
const auto get_command = [](const auto & shift_length) {
@@ -2379,7 +2413,7 @@ TurnSignalInfo calcTurnSignalInfo(
2379
2413
p.vehicle_info .max_longitudinal_offset_m ;
2380
2414
2381
2415
if (signal_prepare_distance < ego_front_to_shift_start) {
2382
- return {} ;
2416
+ return std::make_pair (TurnSignalInfo{}, false ) ;
2383
2417
}
2384
2418
2385
2419
const auto blinker_start_pose = path.path .points .at (shift_line.start_idx ).point .pose ;
@@ -2396,12 +2430,12 @@ TurnSignalInfo calcTurnSignalInfo(
2396
2430
turn_signal_info.turn_signal .command = get_command (relative_shift_length);
2397
2431
2398
2432
if (!p.turn_signal_on_swerving ) {
2399
- return turn_signal_info;
2433
+ return std::make_pair ( turn_signal_info, false ) ;
2400
2434
}
2401
2435
2402
2436
lanelet::ConstLanelet lanelet;
2403
2437
if (!rh->getClosestLaneletWithinRoute (shift_line.end , &lanelet)) {
2404
- return {} ;
2438
+ return std::make_pair (TurnSignalInfo{}, true ) ;
2405
2439
}
2406
2440
2407
2441
const auto left_same_direction_lane = rh->getLeftLanelet (lanelet, true , true );
@@ -2412,14 +2446,25 @@ TurnSignalInfo calcTurnSignalInfo(
2412
2446
const auto has_right_lane =
2413
2447
right_same_direction_lane.has_value () || !right_opposite_lanes.empty ();
2414
2448
2415
- if (!existShiftSideLane (start_shift_length, end_shift_length, !has_left_lane, !has_right_lane)) {
2416
- return {};
2449
+ if (!existShiftSideLane (
2450
+ start_shift_length, end_shift_length, !has_left_lane, !has_right_lane,
2451
+ p.turn_signal_shift_length_threshold )) {
2452
+ return std::make_pair (TurnSignalInfo{}, true );
2417
2453
}
2418
2454
2419
2455
if (!straddleRoadBound (path, shift_line, data.current_lanelets , p.vehicle_info )) {
2420
- return {};
2456
+ return std::make_pair (TurnSignalInfo{}, true );
2457
+ }
2458
+
2459
+ constexpr double STOPPED_THRESHOLD = 0.1 ; // [m/s]
2460
+ if (ego_speed < STOPPED_THRESHOLD) {
2461
+ if (isNearEndOfShift (
2462
+ start_shift_length, end_shift_length, ego_pose.position , data.current_lanelets ,
2463
+ p.turn_signal_shift_length_threshold )) {
2464
+ return std::make_pair (TurnSignalInfo{}, true );
2465
+ }
2421
2466
}
2422
2467
2423
- return turn_signal_info;
2468
+ return std::make_pair ( turn_signal_info, false ) ;
2424
2469
}
2425
2470
} // namespace behavior_path_planner::utils::avoidance
0 commit comments