Apollo  6.0
Open source self driving car software
open_space_roi_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 <algorithm>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "Eigen/Dense"
29 #include "cyber/common/log.h"
30 #include "modules/common/configs/proto/vehicle_config.pb.h"
33 #include "modules/common/vehicle_state/proto/vehicle_state.pb.h"
38 #include "modules/map/proto/map_id.pb.h"
44 
45 namespace apollo {
46 namespace planning {
47 class OpenSpaceRoiDecider : public Decider {
48  public:
49  OpenSpaceRoiDecider(const TaskConfig &config,
50  const std::shared_ptr<DependencyInjector> &injector);
51 
52  private:
53  apollo::common::Status Process(Frame *frame) override;
54 
55  private:
56  // @brief generate the path by vehicle location and return the target parking
57  // spot on that path
58  bool GetParkingSpot(Frame *const frame,
59  std::array<common::math::Vec2d, 4> *vertices,
60  hdmap::Path *nearby_path);
61 
62  // @brief get path from reference line and return vertices of pullover spot
63  bool GetPullOverSpot(Frame *const frame,
64  std::array<common::math::Vec2d, 4> *vertices,
65  hdmap::Path *nearby_path);
66 
67  // @brief Set an origin to normalize the problem for later computation
68  void SetOrigin(Frame *const frame,
69  const std::array<common::math::Vec2d, 4> &vertices);
70  void SetOriginFromADC(Frame *const frame, const hdmap::Path &nearby_path);
71  void SetParkingSpotEndPose(
72  Frame *const frame, const std::array<common::math::Vec2d, 4> &vertices);
73 
74  void SetPullOverSpotEndPose(Frame *const frame);
75  void SetParkAndGoEndPose(Frame *const frame);
76 
77  // @brief Get road boundaries of both sides
78  void GetRoadBoundary(
79  const hdmap::Path &nearby_path, const double center_line_s,
80  const common::math::Vec2d &origin_point, const double origin_heading,
81  std::vector<common::math::Vec2d> *left_lane_boundary,
82  std::vector<common::math::Vec2d> *right_lane_boundary,
83  std::vector<common::math::Vec2d> *center_lane_boundary_left,
84  std::vector<common::math::Vec2d> *center_lane_boundary_right,
85  std::vector<double> *center_lane_s_left,
86  std::vector<double> *center_lane_s_right,
87  std::vector<double> *left_lane_road_width,
88  std::vector<double> *right_lane_road_width);
89 
90  // @brief Get the Road Boundary From Map object
91  void GetRoadBoundaryFromMap(
92  const hdmap::Path &nearby_path, const double center_line_s,
93  const common::math::Vec2d &origin_point, const double origin_heading,
94  std::vector<common::math::Vec2d> *left_lane_boundary,
95  std::vector<common::math::Vec2d> *right_lane_boundary,
96  std::vector<common::math::Vec2d> *center_lane_boundary_left,
97  std::vector<common::math::Vec2d> *center_lane_boundary_right,
98  std::vector<double> *center_lane_s_left,
99  std::vector<double> *center_lane_s_right,
100  std::vector<double> *left_lane_road_width,
101  std::vector<double> *right_lane_road_width);
102 
103  // @brief Check single-side curb and add key points to the boundary
104  void AddBoundaryKeyPoint(
105  const hdmap::Path &nearby_path, const double check_point_s,
106  const double start_s, const double end_s, const bool is_anchor_point,
107  const bool is_left_curb,
108  std::vector<common::math::Vec2d> *center_lane_boundary,
109  std::vector<common::math::Vec2d> *curb_lane_boundary,
110  std::vector<double> *center_lane_s, std::vector<double> *road_width);
111 
112  // @brief "Region of Interest", load map boundary for open space scenario
113  // @param vertices is an array consisting four points describing the
114  // boundary of spot in box. Four points are in sequence of left_top,
115  // left_down, right_down, right_top
116  // ------------------------------------------------------------------
117  //
118  // --> lane_direction
119  //
120  // ----------------left_top right_top--------------------------
121  // - -
122  // - -
123  // - -
124  // - -
125  // left_down-------right_down
126  bool GetParkingBoundary(Frame *const frame,
127  const std::array<common::math::Vec2d, 4> &vertices,
128  const hdmap::Path &nearby_path,
129  std::vector<std::vector<common::math::Vec2d>>
130  *const roi_parking_boundary);
131 
132  bool GetPullOverBoundary(Frame *const frame,
133  const std::array<common::math::Vec2d, 4> &vertices,
134  const hdmap::Path &nearby_path,
135  std::vector<std::vector<common::math::Vec2d>>
136  *const roi_parking_boundary);
137 
138  bool GetParkAndGoBoundary(Frame *const frame, const hdmap::Path &nearby_path,
139  std::vector<std::vector<common::math::Vec2d>>
140  *const roi_parking_boundary);
141 
142  // @brief search target parking spot on the path by vehicle location, if
143  // no return a nullptr in target_parking_spot
144  void SearchTargetParkingSpotOnPath(
145  const hdmap::Path &nearby_path,
146  hdmap::ParkingSpaceInfoConstPtr *target_parking_spot);
147 
148  // @brief if not close enough to parking spot, return false
149  bool CheckDistanceToParkingSpot(
150  const hdmap::Path &nearby_path,
151  const hdmap::ParkingSpaceInfoConstPtr &target_parking_spot);
152 
153  // @brief Helper function for fuse line segments into convex vertices set
154  bool FuseLineSegments(
155  std::vector<std::vector<common::math::Vec2d>> *line_segments_vec);
156 
157  // @brief main process to compute and load info needed by open space planner
158  bool FormulateBoundaryConstraints(
159  const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
160  Frame *const frame);
161 
162  // @brief Represent the obstacles in vertices and load it into
163  // obstacles_vertices_vec_ in clock wise order. Take different approach
164  // towards warm start and distance approach
165  bool LoadObstacleInVertices(
166  const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
167  Frame *const frame);
168 
169  bool FilterOutObstacle(const Frame &frame, const Obstacle &obstacle);
170 
171  // @brief Transform the vertice presentation of the obstacles into linear
172  // inequality as Ax>b
173  bool LoadObstacleInHyperPlanes(Frame *const frame);
174 
175  // @brief Helper function for LoadObstacleInHyperPlanes()
176  bool GetHyperPlanes(const size_t &obstacles_num,
177  const Eigen::MatrixXi &obstacles_edges_num,
178  const std::vector<std::vector<common::math::Vec2d>>
179  &obstacles_vertices_vec,
180  Eigen::MatrixXd *A_all, Eigen::MatrixXd *b_all);
187  bool IsInParkingLot(const double adc_init_x, const double adc_init_y,
188  const double adc_init_heading,
189  std::array<common::math::Vec2d, 4> *parking_lot_vertices);
196  void GetParkSpotFromMap(hdmap::ParkingSpaceInfoConstPtr parking_lot,
197  std::array<common::math::Vec2d, 4> *vertices);
198 
199  private:
200  // @brief parking_spot_id from routing
201  std::string target_parking_spot_id_;
202 
203  const hdmap::HDMap *hdmap_ = nullptr;
204 
205  apollo::common::VehicleParam vehicle_params_;
206 
207  ThreadSafeIndexedObstacles *obstacles_by_frame_;
208 
209  common::VehicleState vehicle_state_;
210 };
211 
212 } // namespace planning
213 } // namespace apollo
This is the class that associates an Obstacle with its path properties. An obstacle&#39;s path properties...
Definition: obstacle.h:60
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
Definition: hdmap_common.h:134
Defines the Vec2d class.
Definition: open_space_roi_decider.h:47
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
Implements a class of 2-dimensional vectors.
Definition: vec2d.h:42
Definition: path.h:215
High-precision map loader interface.
Definition: hdmap.h:53
Definition: decider.h:32
OpenSpaceRoiDecider(const TaskConfig &config, const std::shared_ptr< DependencyInjector > &injector)
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