Apollo  6.0
Open source self driving car software
path_bounds_decider.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 #include <tuple>
26 #include <unordered_map>
27 #include <utility>
28 #include <vector>
29 
30 #include "gtest/gtest.h"
31 
32 #include "modules/planning/proto/planning_config.pb.h"
33 
35 
36 namespace apollo {
37 namespace planning {
38 
39 constexpr double kPathBoundsDeciderHorizon = 100.0;
40 constexpr double kPathBoundsDeciderResolution = 0.5;
41 constexpr double kDefaultLaneWidth = 5.0;
42 constexpr double kDefaultRoadWidth = 20.0;
43 // TODO(all): Update extra tail point base on vehicle speed.
44 constexpr int kNumExtraTailBoundPoint = 20;
45 constexpr double kPulloverLonSearchCoeff = 1.5;
46 constexpr double kPulloverLatSearchCoeff = 1.25;
47 
48 class PathBoundsDecider : public Decider {
49  public:
50  enum class LaneBorrowInfo {
52  NO_BORROW,
54  };
55  PathBoundsDecider(const TaskConfig& config,
56  const std::shared_ptr<DependencyInjector>& injector);
57 
58  private:
64  common::Status Process(Frame* frame,
65  ReferenceLineInfo* reference_line_info) override;
66 
68  // Below are functions called every frame when executing PathBoundsDecider.
69 
72  void InitPathBoundsDecider(const Frame& frame,
73  const ReferenceLineInfo& reference_line_info);
74 
75  common::TrajectoryPoint InferFrontAxeCenterFromRearAxeCenter(
76  const common::TrajectoryPoint& traj_point);
77 
91  common::Status GenerateRegularPathBound(
92  const ReferenceLineInfo& reference_line_info,
93  const LaneBorrowInfo& lane_borrow_info,
94  std::vector<std::tuple<double, double, double>>* const path_bound,
95  std::string* const blocking_obstacle_id,
96  std::string* const borrow_lane_type);
97 
113  common::Status GenerateFallbackPathBound(
114  const ReferenceLineInfo& reference_line_info,
115  std::vector<std::tuple<double, double, double>>* const path_bound);
116 
117  common::Status GenerateLaneChangePathBound(
118  const ReferenceLineInfo& reference_line_info,
119  std::vector<std::tuple<double, double, double>>* const path_bound);
120 
121  common::Status GeneratePullOverPathBound(
122  const Frame& frame, const ReferenceLineInfo& reference_line_info,
123  std::vector<std::tuple<double, double, double>>* const path_bound);
124 
125  int IsPointWithinPathBound(
126  const ReferenceLineInfo& reference_line_info, const double x,
127  const double y,
128  const std::vector<std::tuple<double, double, double>>& path_bound);
129 
130  bool FindDestinationPullOverS(
131  const Frame& frame, const ReferenceLineInfo& reference_line_info,
132  const std::vector<std::tuple<double, double, double>>& path_bound,
133  double* pull_over_s);
134  bool FindEmergencyPullOverS(const ReferenceLineInfo& reference_line_info,
135  double* pull_over_s);
136 
137  bool SearchPullOverPosition(
138  const Frame& frame, const ReferenceLineInfo& reference_line_info,
139  const std::vector<std::tuple<double, double, double>>& path_bound,
140  std::tuple<double, double, double, int>* const pull_over_configuration);
141 
145  void RemoveRedundantPathBoundaries(
146  std::vector<PathBoundary>* const candidate_path_boundaries);
147 
148  bool IsContained(const std::vector<std::pair<double, double>>& lhs,
149  const std::vector<std::pair<double, double>>& rhs);
150 
152  // Below are functions called when generating path bounds.
153 
156  bool InitPathBoundary(
157  const ReferenceLineInfo& reference_line_info,
158  std::vector<std::tuple<double, double, double>>* const path_bound);
159 
165  bool GetBoundaryFromRoads(
166  const ReferenceLineInfo& reference_line_info,
167  std::vector<std::tuple<double, double, double>>* const path_bound);
168 
174  bool GetBoundaryFromLanes(
175  const ReferenceLineInfo& reference_line_info,
176  const LaneBorrowInfo& lane_borrow_info,
177  std::vector<std::tuple<double, double, double>>* const path_bound,
178  std::string* const borrow_lane_type);
179 
185  bool GetBoundaryFromADC(
186  const ReferenceLineInfo& reference_line_info, double ADC_extra_buffer,
187  std::vector<std::tuple<double, double, double>>* const path_bound);
188 
194  bool GetBoundaryFromLanesAndADC(
195  const ReferenceLineInfo& reference_line_info,
196  const LaneBorrowInfo& lane_borrow_info, double ADC_buffer,
197  std::vector<std::tuple<double, double, double>>* const path_bound,
198  std::string* const borrow_lane_type, bool is_fallback_lanechange = false);
199 
204  void UpdatePullOverBoundaryByLaneBoundary(
205  const ReferenceLineInfo& reference_line_info,
206  std::vector<std::tuple<double, double, double>>* const path_bound);
207 
208  void ConvertBoundarySAxisFromLaneCenterToRefLine(
209  const ReferenceLineInfo& reference_line_info,
210  std::vector<std::tuple<double, double, double>>* const path_bound);
211 
212  void GetBoundaryFromLaneChangeForbiddenZone(
213  const ReferenceLineInfo& reference_line_info,
214  std::vector<std::tuple<double, double, double>>* const path_bound);
215 
220  bool GetBoundaryFromStaticObstacles(
221  const PathDecision& path_decision,
222  std::vector<std::tuple<double, double, double>>* const path_boundaries,
223  std::string* const blocking_obstacle_id);
224 
225  std::vector<std::tuple<int, double, double, double, std::string>>
226  SortObstaclesForSweepLine(
227  const IndexedList<std::string, Obstacle>& indexed_obstacles);
228 
229  std::vector<std::vector<std::tuple<double, double, double>>>
230  ConstructSubsequentPathBounds(
231  const std::vector<std::tuple<int, double, double, double, std::string>>&
232  sorted_obstacles,
233  size_t path_idx, size_t obs_idx,
234  std::unordered_map<std::string, std::tuple<bool, double>>* const
235  obs_id_to_details,
236  std::vector<std::tuple<double, double, double>>* const curr_path_bounds);
237 
238  std::vector<std::vector<bool>> DecidePassDirections(
239  double l_min, double l_max,
240  const std::vector<std::tuple<int, double, double, double, std::string>>&
241  new_entering_obstacles);
242 
244  // Below are several helper functions:
245 
249  double GetBufferBetweenADCCenterAndEdge();
250 
261  bool UpdatePathBoundaryWithBuffer(
262  size_t idx, double left_bound, double right_bound,
263  std::vector<std::tuple<double, double, double>>* const path_boundaries,
264  bool is_left_lane_bound = false, bool is_right_lane_bound = false);
265 
275  bool UpdatePathBoundaryAndCenterLineWithBuffer(
276  size_t idx, double left_bound, double right_bound,
277  std::vector<std::tuple<double, double, double>>* const path_boundaries,
278  double* const center_line);
279 
288  bool UpdatePathBoundary(
289  size_t idx, double left_bound, double right_bound,
290  std::vector<std::tuple<double, double, double>>* const path_boundaries);
291 
294  void TrimPathBounds(
295  const int path_blocked_idx,
296  std::vector<std::tuple<double, double, double>>* const path_boundaries);
297 
300  void PathBoundsDebugString(
301  const std::vector<std::tuple<double, double, double>>& path_boundaries);
302 
303  bool CheckLaneBoundaryType(const ReferenceLineInfo& reference_line_info,
304  const double check_s,
305  const LaneBorrowInfo& lane_borrow_info);
306 
307  void RecordDebugInfo(
308  const std::vector<std::tuple<double, double, double>>& path_boundaries,
309  const std::string& debug_name,
310  ReferenceLineInfo* const reference_line_info);
311 
312  private:
313  double adc_frenet_s_ = 0.0;
314  double adc_frenet_sd_ = 0.0;
315  double adc_frenet_l_ = 0.0;
316  double adc_frenet_ld_ = 0.0;
317  double adc_l_to_lane_center_ = 0.0;
318  double adc_lane_width_ = 0.0;
319 
320  FRIEND_TEST(PathBoundsDeciderTest, InitPathBoundary);
321  FRIEND_TEST(PathBoundsDeciderTest, GetBoundaryFromLanesAndADC);
322 };
323 
324 } // namespace planning
325 } // namespace apollo
constexpr double kPulloverLonSearchCoeff
Definition: path_bounds_decider.h:45
constexpr double kPathBoundsDeciderResolution
Definition: path_bounds_decider.h:40
PathDecision represents all obstacle decisions on one path.
Definition: path_decision.h:38
Definition: path_bounds_decider.h:48
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Planning module main class. It processes GPS and IMU as input, to generate planning info...
Frame holds all data for one planning cycle.
Definition: frame.h:61
ReferenceLineInfo holds all data for one reference line.
Definition: reference_line_info.h:54
constexpr double kDefaultLaneWidth
Definition: path_bounds_decider.h:41
constexpr double kPulloverLatSearchCoeff
Definition: path_bounds_decider.h:46
constexpr double kDefaultRoadWidth
Definition: path_bounds_decider.h:42
Definition: decider.h:32
PathBoundsDecider(const TaskConfig &config, const std::shared_ptr< DependencyInjector > &injector)
constexpr double kPathBoundsDeciderHorizon
Definition: path_bounds_decider.h:39
LaneBorrowInfo
Definition: path_bounds_decider.h:50
A general class to denote the return status of an API call. It can either be an OK status for success...
Definition: status.h:43
constexpr int kNumExtraTailBoundPoint
Definition: path_bounds_decider.h:44