@@ -499,7 +499,6 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
499
499
}
500
500
501
501
stop_watch_.tic (__func__);
502
- const auto & p = behavior_determination_param_;
503
502
*debug_data_ptr_ = DebugData ();
504
503
505
504
const auto is_driving_forward = motion_utils::isDrivingForwardWithTwist (traj_points);
@@ -509,17 +508,7 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
509
508
// (1) with a proper label
510
509
// (2) in front of ego
511
510
// (3) not too far from trajectory
512
- const auto target_obstacles = [&]() {
513
- auto target_obstacles = convertToObstacles (traj_points);
514
- // Sort from closest to farthest obstacle to speed up yield
515
- if (p.enable_yield ) {
516
- std::sort (
517
- target_obstacles.begin (), target_obstacles.end (), [](const auto & o1, const auto & o2) {
518
- return o1.ego_to_obstacle_distance < o2.ego_to_obstacle_distance ;
519
- });
520
- }
521
- return target_obstacles;
522
- }();
511
+ const auto target_obstacles = convertToObstacles (traj_points);
523
512
524
513
// 2. Determine ego's behavior against each obstacle from stop, cruise and slow down.
525
514
const auto & [stop_obstacles, cruise_obstacles, slow_down_obstacles] =
@@ -940,63 +929,66 @@ std::optional<std::vector<CruiseObstacle>> ObstacleCruisePlannerNode::findYieldC
940
929
if (obstacles.empty () || traj_points.empty ()) return std::nullopt;
941
930
const auto & p = behavior_determination_param_;
942
931
943
- // obstacles are sorted by closest to farthest, we want to preserve the order
944
- std::vector<std::pair<size_t , Obstacle>> indexed_obstacles;
945
- for (std::size_t i = 0 ; i < obstacles.size (); ++i) {
946
- indexed_obstacles.emplace_back (i, obstacles[i]);
947
- }
948
-
949
- std::vector<std::pair<size_t , Obstacle>> stopped_obstacles;
950
- std::vector<std::pair<size_t , Obstacle>> moving_obstacles;
932
+ std::vector<Obstacle> stopped_obstacles;
933
+ std::vector<Obstacle> moving_obstacles;
951
934
952
935
std::for_each (
953
- indexed_obstacles .begin (), indexed_obstacles .end (),
936
+ obstacles .begin (), obstacles .end (),
954
937
[&stopped_obstacles, &moving_obstacles, &p](const auto & o) {
955
- const bool is_moving = std::hypot (o. second . twist . linear . x , o. second . twist . linear . y ) >
956
- p.stopped_obstacle_velocity_threshold ;
938
+ const bool is_moving =
939
+ std::hypot (o. twist . linear . x , o. twist . linear . y ) > p.stopped_obstacle_velocity_threshold ;
957
940
if (is_moving) {
958
941
const bool is_within_lat_dist_threshold =
959
- o.second . lat_dist_from_obstacle_to_traj < p.yield_lat_distance_threshold ;
942
+ o.lat_dist_from_obstacle_to_traj < p.yield_lat_distance_threshold ;
960
943
if (is_within_lat_dist_threshold) moving_obstacles.push_back (o);
961
944
return ;
962
945
}
963
946
// lat threshold is larger for stopped obstacles
964
947
const bool is_within_lat_dist_threshold =
965
- o.second . lat_dist_from_obstacle_to_traj <
948
+ o.lat_dist_from_obstacle_to_traj <
966
949
p.yield_lat_distance_threshold + p.max_lat_dist_between_obstacles ;
967
950
if (is_within_lat_dist_threshold) stopped_obstacles.push_back (o);
968
951
return ;
969
952
});
970
953
971
954
if (stopped_obstacles.empty () || moving_obstacles.empty ()) return std::nullopt;
955
+
956
+ std::sort (
957
+ stopped_obstacles.begin (), stopped_obstacles.end (), [](const auto & o1, const auto & o2) {
958
+ return o1.ego_to_obstacle_distance < o2.ego_to_obstacle_distance ;
959
+ });
960
+
961
+ std::sort (moving_obstacles.begin (), moving_obstacles.end (), [](const auto & o1, const auto & o2) {
962
+ return o1.ego_to_obstacle_distance < o2.ego_to_obstacle_distance ;
963
+ });
964
+
972
965
std::vector<CruiseObstacle> yield_obstacles;
973
966
for (const auto & moving_obstacle : moving_obstacles) {
974
967
for (const auto & stopped_obstacle : stopped_obstacles) {
975
968
const bool is_moving_obs_behind_of_stopped_obs =
976
- moving_obstacle.first < stopped_obstacle.first ;
969
+ moving_obstacle.ego_to_obstacle_distance < stopped_obstacle.ego_to_obstacle_distance ;
977
970
const bool is_moving_obs_ahead_of_ego_front =
978
- moving_obstacle.second . ego_to_obstacle_distance > vehicle_info_.vehicle_length_m ;
971
+ moving_obstacle.ego_to_obstacle_distance > vehicle_info_.vehicle_length_m ;
979
972
980
973
if (!is_moving_obs_ahead_of_ego_front || !is_moving_obs_behind_of_stopped_obs) continue ;
981
974
982
975
const double lateral_distance_between_obstacles = std::abs (
983
- moving_obstacle.second . lat_dist_from_obstacle_to_traj -
984
- stopped_obstacle.second . lat_dist_from_obstacle_to_traj );
976
+ moving_obstacle.lat_dist_from_obstacle_to_traj -
977
+ stopped_obstacle.lat_dist_from_obstacle_to_traj );
985
978
986
979
const double longitudinal_distance_between_obstacles = std::abs (
987
- moving_obstacle.second .ego_to_obstacle_distance -
988
- stopped_obstacle.second .ego_to_obstacle_distance );
980
+ moving_obstacle.ego_to_obstacle_distance - stopped_obstacle.ego_to_obstacle_distance );
989
981
990
982
const double moving_obstacle_speed =
991
- std::hypot (moving_obstacle.second . twist .linear .x , moving_obstacle. second .twist .linear .y );
983
+ std::hypot (moving_obstacle.twist .linear .x , moving_obstacle.twist .linear .y );
992
984
993
985
const bool are_obstacles_aligned =
994
986
lateral_distance_between_obstacles < p.max_lat_dist_between_obstacles ;
995
987
const bool obstacles_collide_within_threshold_time =
996
988
longitudinal_distance_between_obstacles / moving_obstacle_speed <
997
989
p.max_obstacles_collision_time ;
998
990
if (are_obstacles_aligned && obstacles_collide_within_threshold_time) {
999
- const auto yield_obstacle = createYieldCruiseObstacle (moving_obstacle. second , traj_points);
991
+ const auto yield_obstacle = createYieldCruiseObstacle (moving_obstacle, traj_points);
1000
992
if (yield_obstacle) {
1001
993
yield_obstacles.push_back (*yield_obstacle);
1002
994
}
0 commit comments