38 auto &obstacles_vertices_vec =
40 auto &obstacles_edges_num_vec =
42 size_t obstacles_vertices_vec_num = obstacles_vertices_vec.size();
43 obstacles_edges_num_vec.resize(obstacles_vertices_vec_num, 1);
44 for (
size_t i = 0; i < obstacles_vertices_vec_num; i++) {
45 CHECK_GT(obstacles_vertices_vec[i].size(), 1U);
46 obstacles_edges_num_vec(i, 0) =
47 static_cast<int>(obstacles_vertices_vec[i].size()) - 1;
52 AERROR <<
"fail at LoadObstacleInHyperPlanes()";
59 const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
60 std::vector<double> *
const XYBoundary) {
62 XYBoundary->resize(4);
63 *XYBoundary = {std::numeric_limits<double>::max(),
64 std::numeric_limits<double>::lowest(),
65 std::numeric_limits<double>::max(),
66 std::numeric_limits<double>::lowest()};
67 for (
auto &bound_vec : roi_parking_boundary) {
68 for (
auto &pt : bound_vec) {
69 XYBoundary->at(0) = std::min<double>(XYBoundary->at(0), pt.x());
70 XYBoundary->at(1) = std::max<double>(XYBoundary->at(1), pt.x());
71 XYBoundary->at(2) = std::min<double>(XYBoundary->at(2), pt.y());
72 XYBoundary->at(3) = std::max<double>(XYBoundary->at(3), pt.y());
80 std::vector<std::vector<common::math::Vec2d>> *roi_parking_boundary) {
81 for (
auto &bound_vec : *roi_parking_boundary) {
89 std::vector<common::math::Vec2d> *roi_parking_boundary) {
90 for (
auto &point : *roi_parking_boundary) {
99 *point -= origin_point;
104 const double filtering_distance,
105 const double perception_obstacle_buffer,
106 const std::vector<double> &xy_boundary,
108 std::vector<std::vector<common::math::Vec2d>> *
const
109 roi_parking_boundary) {
111 size_t perception_obstacles_num = 0;
114 for (
const auto &obstacle : obstacles_by_frame->Items()) {
118 ++perception_obstacles_num;
120 Box2d original_box = obstacle->PerceptionBoundingBox();
130 std::vector<Vec2d> vertices_ccw = original_box.
GetAllCorners();
131 std::vector<Vec2d> vertices_cw;
132 while (!vertices_ccw.empty()) {
133 auto current_corner_pt = vertices_ccw.back();
134 vertices_cw.push_back(current_corner_pt);
135 vertices_ccw.pop_back();
140 vertices_cw.push_back(vertices_cw.front());
141 roi_parking_boundary->push_back(vertices_cw);
148 const double filtering_distance,
150 const std::vector<double> &xy_boundary,
158 auto obstacle_center_xy = obstacle_box.
center();
161 if (obstacle_center_xy.x() < xy_boundary[0] ||
162 obstacle_center_xy.x() > xy_boundary[1] ||
163 obstacle_center_xy.y() < xy_boundary[2] ||
164 obstacle_center_xy.y() > xy_boundary[3]) {
169 const auto &end_pose = open_space_info.open_space_end_pose();
170 Vec2d end_pose_x_y(end_pose[0], end_pose[1]);
173 Vec2d vehicle_x_y(vehicle_state.x(), vehicle_state.y());
176 const double vehicle_center_to_obstacle =
177 obstacle_box.DistanceTo(vehicle_x_y);
178 const double end_pose_center_to_obstacle =
179 obstacle_box.DistanceTo(end_pose_x_y);
180 if (vehicle_center_to_obstacle > filtering_distance &&
181 end_pose_center_to_obstacle > filtering_distance) {
199 AERROR <<
"Fail to present obstacle in hyperplane";
206 const size_t &obstacles_num,
207 const Eigen::MatrixXi &obstacles_edges_num,
208 const std::vector<std::vector<Vec2d>> &obstacles_vertices_vec,
209 Eigen::MatrixXd *A_all,
210 Eigen::MatrixXd *b_all) {
211 if (obstacles_num != obstacles_vertices_vec.size()) {
212 AERROR <<
"obstacles_num != obstacles_vertices_vec.size()";
216 A_all->resize(obstacles_edges_num.sum(), 2);
217 b_all->resize(obstacles_edges_num.sum(), 1);
220 double kEpsilon = 1.0e-5;
222 for (
size_t i = 0; i < obstacles_num; ++i) {
223 size_t current_vertice_num = obstacles_edges_num(i, 0);
224 Eigen::MatrixXd A_i(current_vertice_num, 2);
225 Eigen::MatrixXd b_i(current_vertice_num, 1);
228 for (
size_t j = 0; j < current_vertice_num; ++j) {
229 Vec2d v1 = obstacles_vertices_vec[i][j];
230 Vec2d v2 = obstacles_vertices_vec[i][j + 1];
232 Eigen::MatrixXd A_tmp(2, 1), b_tmp(1, 1), ab(2, 1);
234 if (std::abs(v1.
x() - v2.
x()) < kEpsilon) {
235 if (v2.
y() < v1.
y()) {
242 }
else if (std::abs(v1.
y() - v2.
y()) < kEpsilon) {
243 if (v1.
x() < v2.
x()) {
251 Eigen::MatrixXd tmp1(2, 2);
252 tmp1 << v1.
x(), 1, v2.
x(), 1;
253 Eigen::MatrixXd tmp2(2, 1);
254 tmp2 << v1.
y(), v2.
y();
255 ab = tmp1.inverse() * tmp2;
259 if (v1.
x() < v2.
x()) {
269 A_i.block(j, 0, 1, 2) = A_tmp.transpose();
270 b_i.block(j, 0, 1, 1) = b_tmp;
273 A_all->block(counter, 0, A_i.rows(), 2) = A_i;
274 b_all->block(counter, 0, b_i.rows(), 1) = b_i;
275 counter +=
static_cast<int>(current_vertice_num);
281 const Vec2d &origin_point,
282 const double &origin_heading,
286 auto obstacles_vertices_vec =
290 Vec2d end_pose(end_pose_vec->at(0), end_pose_vec->at(1));
292 end_pose_vec->at(0) = end_pose.
x();
293 end_pose_vec->at(1) = end_pose.
y();
294 end_pose_vec->at(2) -= origin_heading;
300 for (
size_t i = 0; i < polygon.size(); i++) {
301 if (i + 1 < polygon.size()) {
302 s += polygon.at(i).x() * polygon.at(i + 1).y() -
303 polygon.at(i).y() * polygon.at(i + 1).x();
305 s += polygon.at(i).x() * polygon.at(0).y() -
306 polygon.at(i).y() * polygon.at(0).x();
317 std::vector<Vec2d> *polygon) {
320 ADEBUG <<
"point is anticlockwise,reverse";
321 std::reverse(polygon->begin(), polygon->end());
331 double min_dist = std::numeric_limits<double>::max();
332 size_t min_index = 0;
333 for (
size_t i = 0; i < points->size(); i++) {
334 double s = 0.0, l = 0.0;
336 ADEBUG << std::fixed << points->at(i).x() <<
"," << points->at(i).y()
337 <<
"sl" << s <<
"," << l;
338 if (std::fabs(s) + 2.0 * std::fabs(l) < min_dist) {
339 min_dist = std::fabs(s) + 2.0 * std::fabs(l);
343 std::vector<Vec2d> tmp_points(*points);
344 for (
size_t i = 0; i < points->size(); i++) {
345 tmp_points[i] = points->at((i + min_index) % points->size());
347 for (
size_t i = 0; i < points->size(); i++) {
348 points->at(i) = tmp_points[i];
Rectangular (undirected) bounding box in 2-D.
void GetAllCorners(std::vector< Vec2d > *const corners) const
Getter of the corners of the box
void LateralExtend(const double extension_length)
const Vec2d & center() const
Getter of the center of the box
void LongitudinalExtend(const double extension_length)
Extend the box longitudinally
Implements a class of 2-dimensional vectors.
void SelfRotate(const double angle)
rotate the vector itself by angle.
double y() const
Getter for y component
double x() const
Getter for x component
bool GetProjection(const common::math::Vec2d &point, double *accumulate_s, double *lateral) const
Frame holds all data for one planning cycle.
const OpenSpaceInfo & open_space_info() const
const common::VehicleState & vehicle_state() const
ThreadSafeIndexedObstacles * GetObstacleList()
This is the class that associates an Obstacle with its path properties.
const common::math::Box2d & PerceptionBoundingBox() const
std::vector< double > * mutable_ROI_xy_boundary()
Eigen::MatrixXd * mutable_obstacles_b()
Eigen::MatrixXd * mutable_obstacles_A()
std::vector< double > * mutable_open_space_end_pose()
const std::vector< std::vector< common::math::Vec2d > > & obstacles_vertices_vec() const
size_t obstacles_num() const
common::math::Vec2d * mutable_origin_point()
Eigen::MatrixXi * mutable_obstacles_edges_num()
std::vector< std::vector< common::math::Vec2d > > * mutable_obstacles_vertices_vec()
const Eigen::MatrixXi & obstacles_edges_num() const
void set_origin_heading(const double original_heading)
void set_obstacles_num(const size_t obstacles_num)
static bool AdjustPointsOrderToClockwise(std::vector< Vec2d > *polygon)
static bool LoadObstacleInHyperPlanes(OpenSpaceInfo *const open_space_info)
brief Transform the vertice presentation of the obstacles into linear inequality as Ax>b
static bool FormulateBoundaryConstraints(OpenSpaceInfo *const open_space_info)
main process to compute and load info needed by open space planner
static bool LoadObstacles(const double filtering_distance, const double perception_obstacle_buffer, const std::vector< double > &xy_boundary, Frame *const frame, std::vector< std::vector< common::math::Vec2d > > *const roi_parking_boundary)
Load obstacle polygon to roi_boundary in clock wise order
static bool UpdateParkingPointsOrder(const apollo::hdmap::Path &nearby_path, std::vector< Vec2d > *points)
static void TransformByOriginPoint(const common::math::Vec2d &origin_point, const double heading, std::vector< std::vector< common::math::Vec2d > > *roi_parking_boundary)
static bool IsPolygonClockwise(const std::vector< Vec2d > &polygon)
static void GetRoiXYBoundary(const std::vector< std::vector< common::math::Vec2d > > &roi_parking_boundary, std::vector< double > *const XYBoundary)
get XY boundary which is minmax x or y in roi boundary
static bool FilterOutObstacle(const double filtering_distance, const Frame &frame, const std::vector< double > &xy_boundary, const Obstacle &obstacle)
is obstacle can be filterd out, filtered by distance and roi XY bound
static bool GetHyperPlanes(const size_t &obstacles_num, const Eigen::MatrixXi &obstacles_edges_num, const std::vector< std::vector< Vec2d > > &obstacles_vertices_vec, Eigen::MatrixXd *A_all, Eigen::MatrixXd *b_all)
Planning module main class.