@@ -2141,48 +2141,65 @@ bool RouteHandler::planPathLaneletsBetweenCheckpoints(
2141
2141
2142
2142
// Find lanelets for goal point.
2143
2143
lanelet::ConstLanelet goal_lanelet;
2144
- if (!lanelet::utils::query::getClosestLanelet (road_lanelets_, goal_checkpoint, &goal_lanelet)) {
2145
- RCLCPP_WARN_STREAM (
2146
- logger_, " Failed to find closest lanelet."
2147
- << std::endl
2148
- << " - start checkpoint: " << toString (start_checkpoint) << std::endl
2149
- << " - goal checkpoint: " << toString (goal_checkpoint) << std::endl);
2150
- return false ;
2144
+ lanelet::ConstLanelets goal_lanelets;
2145
+ if (!lanelet::utils::query::getCurrentLanelets (
2146
+ road_lanelets_, goal_checkpoint, &goal_lanelets)) {
2147
+ if (!lanelet::utils::query::getClosestLanelet (
2148
+ road_lanelets_, goal_checkpoint, &goal_lanelet)) {
2149
+ RCLCPP_WARN_STREAM (
2150
+ logger_, " Failed to find current lanelet."
2151
+ << std::endl
2152
+ << " - start checkpoint: " << toString (start_checkpoint) << std::endl
2153
+ << " - goal checkpoint: " << toString (goal_checkpoint) << std::endl);
2154
+ return false ;
2155
+ }
2156
+ goal_lanelets = {goal_lanelet};
2151
2157
}
2152
2158
2153
2159
lanelet::Optional<lanelet::routing::Route> optional_route;
2154
2160
std::vector<lanelet::ConstLanelets> candidate_paths;
2155
2161
lanelet::routing::LaneletPath shortest_path;
2156
2162
bool is_route_found = false ;
2157
2163
2164
+ lanelet::routing::LaneletPath drivable_lane_path;
2165
+ double shortest_path_length2d = std::numeric_limits<double >::max ();
2158
2166
double smallest_angle_diff = std::numeric_limits<double >::max ();
2159
2167
constexpr double yaw_threshold = M_PI / 2.0 ;
2160
2168
2161
2169
for (const auto & st_llt : start_lanelets) {
2162
- // check if the angle difference between start_checkpoint and start lanelet center line
2163
- // orientation is in yaw_threshold range
2164
- double lanelet_angle = lanelet::utils::getLaneletAngle (st_llt, start_checkpoint.position );
2165
- double pose_yaw = tf2::getYaw (start_checkpoint.orientation );
2166
- double angle_diff = std::abs (autoware_utils::normalize_radian (lanelet_angle - pose_yaw));
2167
-
2168
- bool is_proper_angle = angle_diff <= std::abs (yaw_threshold);
2169
-
2170
- optional_route = routing_graph_ptr_->getRoute (st_llt, goal_lanelet, 0 );
2171
- if (!optional_route || !is_proper_angle) {
2172
- RCLCPP_ERROR_STREAM (
2173
- logger_, " Failed to find a proper route!"
2174
- << std::endl
2175
- << " - start checkpoint: " << toString (start_checkpoint) << std::endl
2176
- << " - goal checkpoint: " << toString (goal_checkpoint) << std::endl
2177
- << " - start lane id: " << st_llt.id () << std::endl
2178
- << " - goal lane id: " << goal_lanelet.id () << std::endl);
2179
- continue ;
2180
- }
2181
- is_route_found = true ;
2182
- if (angle_diff < smallest_angle_diff) {
2183
- smallest_angle_diff = angle_diff;
2184
- shortest_path = optional_route->shortestPath ();
2185
- start_lanelet = st_llt;
2170
+ for (const auto & gl_llt : goal_lanelets) {
2171
+ // check if the angle difference between start_checkpoint and start lanelet center line
2172
+ // orientation is in yaw_threshold range
2173
+
2174
+ double lanelet_angle = lanelet::utils::getLaneletAngle (st_llt, start_checkpoint.position );
2175
+ double pose_yaw = tf2::getYaw (start_checkpoint.orientation );
2176
+ double angle_diff = std::abs (autoware_utils::normalize_radian (lanelet_angle - pose_yaw));
2177
+
2178
+ bool is_proper_angle = angle_diff <= std::abs (yaw_threshold);
2179
+
2180
+ if (angle_diff < smallest_angle_diff) {
2181
+ smallest_angle_diff = angle_diff;
2182
+ is_proper_angle = true ;
2183
+ }
2184
+
2185
+ optional_route = routing_graph_ptr_->getRoute (st_llt, gl_llt, 0 );
2186
+ if (!optional_route || !is_proper_angle) {
2187
+ RCLCPP_ERROR_STREAM (
2188
+ logger_, " Failed to find a proper route!"
2189
+ << std::endl
2190
+ << " - start checkpoint: " << toString (start_checkpoint) << std::endl
2191
+ << " - goal checkpoint: " << toString (goal_checkpoint) << std::endl
2192
+ << " - start lane id: " << st_llt.id () << std::endl
2193
+ << " - goal lane id: " << gl_llt.id () << std::endl);
2194
+ } else {
2195
+ is_route_found = true ;
2196
+ if (optional_route->length2d () < shortest_path_length2d) {
2197
+ shortest_path_length2d = optional_route->length2d ();
2198
+ shortest_path = optional_route->shortestPath ();
2199
+ start_lanelet = st_llt;
2200
+ goal_lanelet = gl_llt;
2201
+ }
2202
+ }
2186
2203
}
2187
2204
}
2188
2205
0 commit comments