39 size_t obstacles_vertices_vec_num = obstacles_vertices_vec.size();
40 obstacles_edges_num_vec.resize(obstacles_vertices_vec_num, 1);
41 for (
size_t i = 0; i < obstacles_vertices_vec_num; i++) {
42 CHECK_GT(obstacles_vertices_vec[i].size(), 1U);
43 obstacles_edges_num_vec(i, 0) =
static_cast<int>(obstacles_vertices_vec[i].size()) - 1;
48 AERROR <<
"fail at LoadObstacleInHyperPlanes()";
55 const std::vector<std::vector<common::math::Vec2d>> &roi_parking_boundary,
56 std::vector<double> *
const XYBoundary) {
58 XYBoundary->resize(4);
60 = {std::numeric_limits<double>::max(),
61 std::numeric_limits<double>::lowest(),
62 std::numeric_limits<double>::max(),
63 std::numeric_limits<double>::lowest()};
64 for (
auto &bound_vec : roi_parking_boundary) {
65 for (
auto &pt : bound_vec) {
66 XYBoundary->at(0) = std::min<double>(XYBoundary->at(0), pt.x());
67 XYBoundary->at(1) = std::max<double>(XYBoundary->at(1), pt.x());
68 XYBoundary->at(2) = std::min<double>(XYBoundary->at(2), pt.y());
69 XYBoundary->at(3) = std::max<double>(XYBoundary->at(3), pt.y());
77 std::vector<std::vector<common::math::Vec2d>> *roi_parking_boundary) {
78 for (
auto &bound_vec : *roi_parking_boundary) {
86 std::vector<common::math::Vec2d> *roi_parking_boundary) {
87 for (
auto &point : *roi_parking_boundary) {
96 *point -= origin_point;
101 const double filtering_distance,
102 const double perception_obstacle_buffer,
103 const std::vector<double> &xy_boundary,
105 std::vector<std::vector<common::math::Vec2d>> *
const roi_parking_boundary) {
107 size_t perception_obstacles_num = 0;
110 for (
const auto &obstacle : obstacles_by_frame->Items()) {
114 ++perception_obstacles_num;
116 Box2d original_box = obstacle->PerceptionBoundingBox();
126 std::vector<Vec2d> vertices_ccw = original_box.
GetAllCorners();
127 std::vector<Vec2d> vertices_cw;
128 while (!vertices_ccw.empty()) {
129 auto current_corner_pt = vertices_ccw.back();
130 vertices_cw.push_back(current_corner_pt);
131 vertices_ccw.pop_back();
136 vertices_cw.push_back(vertices_cw.front());
137 roi_parking_boundary->push_back(vertices_cw);
144 const double filtering_distance,
146 const std::vector<double> &xy_boundary,
153 const auto &origin_point = open_space_info.
origin_point();
154 const auto &origin_heading = open_space_info.origin_heading();
156 auto obstacle_center_xy = obstacle_box.
center();
159 obstacle_center_xy -= origin_point;
160 obstacle_center_xy.
SelfRotate(-origin_heading);
161 if (obstacle_center_xy.x() < xy_boundary[0] || obstacle_center_xy.x() > xy_boundary[1]
162 || obstacle_center_xy.y() < xy_boundary[2] || obstacle_center_xy.y() > xy_boundary[3]) {
167 const auto &end_pose = open_space_info.open_space_end_pose();
168 Vec2d end_pose_x_y(end_pose[0], end_pose[1]);
170 end_pose_x_y += origin_point;
173 Vec2d vehicle_x_y(vehicle_state.x(), vehicle_state.y());
176 const double vehicle_center_to_obstacle = obstacle_box.DistanceTo(vehicle_x_y);
177 const double end_pose_center_to_obstacle = obstacle_box.DistanceTo(end_pose_x_y);
178 if (vehicle_center_to_obstacle > filtering_distance && end_pose_center_to_obstacle > filtering_distance) {
194 AERROR <<
"Fail to present obstacle in hyperplane";
201 const size_t &obstacles_num,
202 const Eigen::MatrixXi &obstacles_edges_num,
203 const std::vector<std::vector<Vec2d>> &obstacles_vertices_vec,
204 Eigen::MatrixXd *A_all,
205 Eigen::MatrixXd *b_all) {
206 if (obstacles_num != obstacles_vertices_vec.size()) {
207 AERROR <<
"obstacles_num != obstacles_vertices_vec.size()";
211 A_all->resize(obstacles_edges_num.sum(), 2);
212 b_all->resize(obstacles_edges_num.sum(), 1);
215 double kEpsilon = 1.0e-5;
217 for (
size_t i = 0; i < obstacles_num; ++i) {
218 size_t current_vertice_num = obstacles_edges_num(i, 0);
219 Eigen::MatrixXd A_i(current_vertice_num, 2);
220 Eigen::MatrixXd b_i(current_vertice_num, 1);
223 for (
size_t j = 0; j < current_vertice_num; ++j) {
224 Vec2d v1 = obstacles_vertices_vec[i][j];
225 Vec2d v2 = obstacles_vertices_vec[i][j + 1];
227 Eigen::MatrixXd A_tmp(2, 1), b_tmp(1, 1), ab(2, 1);
229 if (std::abs(v1.
x() - v2.
x()) < kEpsilon) {
230 if (v2.
y() < v1.
y()) {
237 }
else if (std::abs(v1.
y() - v2.
y()) < kEpsilon) {
238 if (v1.
x() < v2.
x()) {
246 Eigen::MatrixXd tmp1(2, 2);
247 tmp1 << v1.
x(), 1, v2.
x(), 1;
248 Eigen::MatrixXd tmp2(2, 1);
249 tmp2 << v1.
y(), v2.
y();
250 ab = tmp1.inverse() * tmp2;
254 if (v1.
x() < v2.
x()) {
264 A_i.block(j, 0, 1, 2) = A_tmp.transpose();
265 b_i.block(j, 0, 1, 1) = b_tmp;
268 A_all->block(counter, 0, A_i.rows(), 2) = A_i;
269 b_all->block(counter, 0, b_i.rows(), 1) = b_i;
270 counter +=
static_cast<int>(current_vertice_num);
276 const Vec2d &origin_point,
277 const double &origin_heading,
284 Vec2d end_pose(end_pose_vec->at(0), end_pose_vec->at(1));
286 end_pose_vec->at(0) = end_pose.
x();
287 end_pose_vec->at(1) = end_pose.
y();
288 end_pose_vec->at(2) -= origin_heading;
294 for (
size_t i = 0; i < polygon.size(); i++) {
295 if (i + 1 < polygon.size()) {
296 s += polygon.at(i).x() * polygon.at(i + 1).y() - polygon.at(i).y() * polygon.at(i + 1).x();
298 s += polygon.at(i).x() * polygon.at(0).y() - polygon.at(i).y() * polygon.at(0).x();
311 ADEBUG <<
"point is anticlockwise,reverse";
312 std::reverse(polygon->begin(), polygon->end());
321 double min_dist = std::numeric_limits<double>::max();
322 size_t min_index = 0;
324 for (
size_t i = 0; i < points->size(); i++) {
325 double s = 0.0, l = 0.0;
328 ADEBUG << std::fixed << points->at(i).x() <<
"," << points->at(i).y() <<
"sl" << s <<
"," << l;
329 if (std::fabs(s) + 2.0 * std::fabs(l) < min_dist) {
330 min_dist = std::fabs(s) + 2.0 * std::fabs(l);
334 std::vector<Vec2d> tmp_points(*points);
335 for (
size_t i = 0; i < points->size(); i++) {
336 tmp_points[i] = points->at((i + min_index) % points->size());
339 for (
size_t i = 0; i < points->size(); i++) {
340 points->at(i) = tmp_points[i];
343 points->at(0) = tmp_points[0];
344 for (
size_t i = points->size() - 1; i > 0; i--) {
345 points->at(points->size() - 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()
const common::math::Vec2d & origin_point() const
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.