Apollo 11.0
自动驾驶开放平台
open_space_roi_decider.h
浏览该文件的文档.
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
30#include "modules/common/vehicle_state/proto/vehicle_state.pb.h"
31#include "modules/common_msgs/config_msgs/vehicle_config.pb.h"
32#include "modules/common_msgs/map_msgs/map_id.pb.h"
33#include "modules/planning/tasks/open_space_roi_decider/proto/open_space_roi_decider.pb.h"
34
35#include "cyber/common/log.h"
48
49namespace apollo {
50namespace planning {
53 std::string parking_id;
54 // left_top right_top right_down left_down
55 std::vector<common::math::Vec2d> corner_points;
57 bool is_on_left = false;
58};
59
61 public:
62 bool Init(const std::string &config_dir, const std::string &name,
63 const std::shared_ptr<DependencyInjector> &injector) override;
64
65 private:
66 apollo::common::Status Process(Frame *frame) override;
67
68 private:
69 // @brief generate the path by vehicle location and return the target parking
70 // spot on that path
71 bool GetParkingSpot(Frame *const frame, ParkingInfo *parking_info);
72
73 // @brief get path from reference line and return vertices of pullover spot
74 bool GetPullOverSpot(Frame *const frame,
75 std::array<common::math::Vec2d, 4> *vertices,
76 hdmap::Path *nearby_path);
77
78 // @brief Set an origin to normalize the problem for later computation
79 void SetOrigin(const ParkingInfo &parking_info, Frame *const frame);
80 void SetOrigin(Frame *const frame,
81 const std::array<common::math::Vec2d, 4> &vertices);
82 void SetOriginFromADC(Frame *const frame, const hdmap::Path &nearby_path);
83 void SetParkingSpotEndPose(const ParkingInfo &parking_info,
84 Frame *const frame);
85
86 void SetPullOverSpotEndPose(Frame *const frame);
87 void SetParkAndGoEndPose(Frame *const frame);
88
89 // @brief Get road boundaries of both sides
90 void GetRoadBoundary(
91 const hdmap::Path &nearby_path, const double center_line_s,
92 const common::math::Vec2d &origin_point, const double origin_heading,
93 std::vector<common::math::Vec2d> *left_lane_boundary,
94 std::vector<common::math::Vec2d> *right_lane_boundary,
95 std::vector<common::math::Vec2d> *center_lane_boundary_left,
96 std::vector<common::math::Vec2d> *center_lane_boundary_right,
97 std::vector<double> *center_lane_s_left,
98 std::vector<double> *center_lane_s_right,
99 std::vector<double> *left_lane_road_width,
100 std::vector<double> *right_lane_road_width);
101
102 // @brief Get the Road Boundary From Map object
103 void GetRoadBoundaryFromMap(
104 const hdmap::Path &nearby_path, const double center_line_s,
105 const common::math::Vec2d &origin_point, const double origin_heading,
106 std::vector<common::math::Vec2d> *left_lane_boundary,
107 std::vector<common::math::Vec2d> *right_lane_boundary,
108 std::vector<common::math::Vec2d> *center_lane_boundary_left,
109 std::vector<common::math::Vec2d> *center_lane_boundary_right,
110 std::vector<double> *center_lane_s_left,
111 std::vector<double> *center_lane_s_right,
112 std::vector<double> *left_lane_road_width,
113 std::vector<double> *right_lane_road_width);
114
115 // @brief Check single-side curb and add key points to the boundary
116 void AddBoundaryKeyPoint(
117 const hdmap::Path &nearby_path, const double check_point_s,
118 const double start_s, const double end_s, const bool is_anchor_point,
119 const bool is_left_curb,
120 std::vector<common::math::Vec2d> *center_lane_boundary,
121 std::vector<common::math::Vec2d> *curb_lane_boundary,
122 std::vector<double> *center_lane_s, std::vector<double> *road_width);
123
124 // @brief "Region of Interest", load map boundary for open space scenario
125 // @param vertices is an array consisting four points describing the
126 // boundary of spot in box. Four points are in sequence of left_top,
127 // left_down, right_down, right_top
128 // ------------------------------------------------------------------
129 //
130 // --> lane_direction
131 //
132 // ----------------left_top right_top--------------------------
133 // - -
134 // - -
135 // - -
136 // - -
137 // left_down-------right_down
138 bool GetParkingBoundary(const ParkingInfo &parking_info,
139 const hdmap::Path &nearby_path, Frame *const frame,
140 std::vector<std::vector<common::math::Vec2d>>
141 *const roi_parking_boundary);
142
143 bool GetParkingOutBoundary(const hdmap::Path &nearby_path, Frame *const frame,
144 std::vector<std::vector<common::math::Vec2d>>
145 *const roi_parking_boundary);
146
147 bool GetPullOverBoundary(Frame *const frame,
148 const std::array<common::math::Vec2d, 4> &vertices,
149 const hdmap::Path &nearby_path,
150 std::vector<std::vector<common::math::Vec2d>>
151 *const roi_parking_boundary);
152
153 bool GetParkAndGoBoundary(Frame *const frame, const hdmap::Path &nearby_path,
154 std::vector<std::vector<common::math::Vec2d>>
155 *const roi_parking_boundary);
156
157 // @brief search target parking spot on the path by vehicle location, if
158 // no return a nullptr in target_parking_spot
159 void SearchTargetParkingSpotOnPath(
160 const hdmap::Path &nearby_path,
161 hdmap::ParkingSpaceInfoConstPtr *target_parking_spot);
162
163 // @brief Helper function for fuse line segments into convex vertices set
164 bool FuseLineSegments(
165 std::vector<std::vector<common::math::Vec2d>> *line_segments_vec);
166
167 // @brief main process to compute and load info needed by open space planner
168 bool FormulateBoundaryConstraints(
169 const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
170 Frame *const frame);
171
172 // @brief Represent the obstacles in vertices and load it into
173 // obstacles_vertices_vec_ in clock wise order. Take different approach
174 // towards warm start and distance approach
175 bool LoadObstacleInVertices(
176 const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
177 Frame *const frame);
178
179 bool FilterOutObstacle(const Frame &frame, const Obstacle &obstacle);
180
181 // @brief Transform the vertice presentation of the obstacles into linear
182 // inequality as Ax>b
183 bool LoadObstacleInHyperPlanes(Frame *const frame);
184
185 // @brief Helper function for LoadObstacleInHyperPlanes()
186 bool GetHyperPlanes(const size_t &obstacles_num,
187 const Eigen::MatrixXi &obstacles_edges_num,
188 const std::vector<std::vector<common::math::Vec2d>>
189 &obstacles_vertices_vec,
190 Eigen::MatrixXd *A_all, Eigen::MatrixXd *b_all);
197 bool IsInParkingLot(const double adc_init_x, const double adc_init_y,
198 const double adc_init_heading,
199 std::array<common::math::Vec2d, 4> *parking_lot_vertices);
206 void GetParkSpotFromMap(hdmap::ParkingSpaceInfoConstPtr parking_lot,
207 std::array<common::math::Vec2d, 4> *vertices);
208
215 void GetAllLaneSegments(const routing::RoutingResponse &routing_response,
216 std::vector<routing::LaneSegment> *routing_segments);
217
218 bool GetNearbyPath(const apollo::routing::RoutingResponse &routing_response,
219 const hdmap::ParkingSpaceInfoConstPtr &parking_spot,
220 std::shared_ptr<hdmap::Path> *nearby_path);
221 bool AdjustPointsOrderToClockwise(std::vector<common::math::Vec2d> *polygon);
222
223 bool AddParkingSpaceBoundary(Frame *const frame,
224 const hdmap::Path &nearby_path,
225 std::vector<std::vector<common::math::Vec2d>>
226 *const roi_parking_boundary);
227
228 private:
229 // @brief parking_spot_id from routing
230 std::string target_parking_spot_id_;
231 std::shared_ptr<apollo::hdmap::Path> nearby_path_;
232 const hdmap::HDMap *hdmap_ = nullptr;
233
234 apollo::common::VehicleParam vehicle_params_;
235
236 ThreadSafeIndexedObstacles *obstacles_by_frame_;
237
238 common::VehicleState vehicle_state_;
240 bool is_parking_out = false;
241};
242
244 Task)
245
246} // namespace planning
247} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
High-precision map loader interface.
Definition hdmap.h:54
Frame holds all data for one planning cycle.
Definition frame.h:62
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
Planning module main class.
#define CYBER_PLUGIN_MANAGER_REGISTER_PLUGIN(name, base)
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
class register implement
Definition arena_queue.h:37
std::vector< common::math::Vec2d > corner_points
Defines the Vec2d class.