@@ -1243,11 +1243,13 @@ lanelet::ConstLanelets getCurrentLanesFromPath(
1243
1243
throw std::logic_error (" empty path." );
1244
1244
}
1245
1245
1246
- if (path.points .front ().lane_ids .empty ()) {
1246
+ const auto idx = planner_data->findEgoIndex (path.points );
1247
+
1248
+ if (path.points .at (idx).lane_ids .empty ()) {
1247
1249
throw std::logic_error (" empty lane ids." );
1248
1250
}
1249
1251
1250
- const auto start_id = path.points .front ( ).lane_ids .front ();
1252
+ const auto start_id = path.points .at (idx ).lane_ids .front ();
1251
1253
const auto start_lane = planner_data->route_handler ->getLaneletsFromId (start_id);
1252
1254
const auto & p = planner_data->parameters ;
1253
1255
@@ -1794,6 +1796,7 @@ AvoidLineArray combineRawShiftLinesWithUniqueCheck(
1794
1796
}
1795
1797
1796
1798
lanelet::ConstLanelets getAdjacentLane (
1799
+ const lanelet::ConstLanelet & current_lane,
1797
1800
const std::shared_ptr<const PlannerData> & planner_data,
1798
1801
const std::shared_ptr<AvoidanceParameters> & parameters, const bool is_right_shift)
1799
1802
{
@@ -1802,18 +1805,17 @@ lanelet::ConstLanelets getAdjacentLane(
1802
1805
const auto & backward_distance = parameters->safety_check_backward_distance ;
1803
1806
const auto & vehicle_pose = planner_data->self_odometry ->pose .pose ;
1804
1807
1805
- lanelet::ConstLanelet current_lane;
1806
- if (!rh->getClosestLaneletWithinRoute (vehicle_pose, ¤t_lane)) {
1807
- RCLCPP_ERROR (
1808
- rclcpp::get_logger (" behavior_path_planner" ).get_child (" avoidance" ),
1809
- " failed to find closest lanelet within route!!!" );
1810
- return {}; // TODO(Satoshi Ota)
1811
- }
1812
-
1813
1808
const auto ego_succeeding_lanes =
1814
1809
rh->getLaneletSequence (current_lane, vehicle_pose, backward_distance, forward_distance);
1815
1810
1816
1811
lanelet::ConstLanelets lanes{};
1812
+
1813
+ const auto exist = [&lanes](const auto id) {
1814
+ const auto itr = std::find_if (
1815
+ lanes.begin (), lanes.end (), [&id](const auto & lane) { return lane.id () == id; });
1816
+ return itr != lanes.end ();
1817
+ };
1818
+
1817
1819
for (const auto & lane : ego_succeeding_lanes) {
1818
1820
const auto opt_left_lane = rh->getLeftLanelet (lane, true , false );
1819
1821
if (!is_right_shift && opt_left_lane) {
@@ -1828,6 +1830,20 @@ lanelet::ConstLanelets getAdjacentLane(
1828
1830
const auto right_opposite_lanes = rh->getRightOppositeLanelets (lane);
1829
1831
if (is_right_shift && !right_opposite_lanes.empty ()) {
1830
1832
lanes.push_back (right_opposite_lanes.front ());
1833
+
1834
+ for (const auto & prev_lane : rh->getPreviousLanelets (right_opposite_lanes.front ())) {
1835
+ if (!exist (prev_lane.id ())) {
1836
+ lanes.push_back (prev_lane);
1837
+ }
1838
+ }
1839
+ }
1840
+ }
1841
+
1842
+ for (const auto & lane : lanes) {
1843
+ for (const auto & next_lane : rh->getNextLanelets (lane)) {
1844
+ if (!exist (next_lane.id ())) {
1845
+ lanes.push_back (next_lane);
1846
+ }
1831
1847
}
1832
1848
}
1833
1849
@@ -1881,9 +1897,16 @@ std::vector<ExtendedPredictedObject> getSafetyCheckTargetObjects(
1881
1897
return ret;
1882
1898
}();
1883
1899
1900
+ lanelet::ConstLanelet closest_lanelet;
1901
+ const auto & ego_pose = planner_data->self_odometry ->pose .pose ;
1902
+ if (!lanelet::utils::query::getClosestLanelet (
1903
+ data.current_lanelets , ego_pose, &closest_lanelet)) {
1904
+ return {};
1905
+ }
1906
+
1884
1907
// check right lanes
1885
1908
if (check_right_lanes) {
1886
- const auto check_lanes = getAdjacentLane (planner_data, p, true );
1909
+ const auto check_lanes = getAdjacentLane (closest_lanelet, planner_data, p, true );
1887
1910
1888
1911
if (p->check_other_object ) {
1889
1912
const auto [targets, others] = utils::path_safety_checker::separateObjectsByLanelets (
@@ -1905,7 +1928,7 @@ std::vector<ExtendedPredictedObject> getSafetyCheckTargetObjects(
1905
1928
1906
1929
// check left lanes
1907
1930
if (check_left_lanes) {
1908
- const auto check_lanes = getAdjacentLane (planner_data, p, false );
1931
+ const auto check_lanes = getAdjacentLane (closest_lanelet, planner_data, p, false );
1909
1932
1910
1933
if (p->check_other_object ) {
1911
1934
const auto [targets, others] = utils::path_safety_checker::separateObjectsByLanelets (
0 commit comments