Apollo 11.0
自动驾驶开放平台
apollo::planning::OpenSpaceRoiUtil类 参考

#include <open_space_roi_util.h>

apollo::planning::OpenSpaceRoiUtil 的协作图:

静态 Public 成员函数

static bool FormulateBoundaryConstraints (OpenSpaceInfo *const open_space_info)
 main process to compute and load info needed by open space planner
 
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 void TransformByOriginPoint (const common::math::Vec2d &origin_point, const double heading, std::vector< std::vector< common::math::Vec2d > > *roi_parking_boundary)
 
static void TransformByOriginPoint (const common::math::Vec2d &origin_point, const double heading, std::vector< common::math::Vec2d > *roi_parking_boundary)
 
static void TransformByOriginPoint (const common::math::Vec2d &origin_point, const double heading, common::math::Vec2d *point)
 
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 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 LoadObstacleInHyperPlanes (OpenSpaceInfo *const open_space_info)
 brief Transform the vertice presentation of the obstacles into linear inequality as Ax>b
 
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)
 
static void TransformByOriginPoint (const Vec2d &origin_point, const double &origin_heading, OpenSpaceInfo *open_space_info)
 
static bool IsPolygonClockwise (const std::vector< Vec2d > &polygon)
 
static bool AdjustPointsOrderToClockwise (std::vector< Vec2d > *polygon)
 
static bool UpdateParkingPointsOrder (const apollo::hdmap::Path &nearby_path, std::vector< Vec2d > *points)
 

详细描述

在文件 open_space_roi_util.h36 行定义.

成员函数说明

◆ AdjustPointsOrderToClockwise()

bool apollo::planning::OpenSpaceRoiUtil::AdjustPointsOrderToClockwise ( std::vector< Vec2d > *  polygon)
static

在文件 open_space_roi_util.cc308 行定义.

308 {
309 if (!IsPolygonClockwise(*polygon)) {
310 // counter clockwise reverse it
311 ADEBUG << "point is anticlockwise,reverse";
312 std::reverse(polygon->begin(), polygon->end());
313 return true;
314 } else {
315 return false;
316 }
317}
static bool IsPolygonClockwise(const std::vector< Vec2d > &polygon)
#define ADEBUG
Definition log.h:41

◆ FilterOutObstacle()

bool apollo::planning::OpenSpaceRoiUtil::FilterOutObstacle ( const double  filtering_distance,
const Frame frame,
const std::vector< double > &  xy_boundary,
const Obstacle obstacle 
)
static

is obstacle can be filterd out, filtered by distance and roi XY bound

参数
xy_boundaryfileter obstacle which out of xy boundary
filtering_distancefilter out distance which is far away from adc
返回
true can be filtered out

在文件 open_space_roi_util.cc143 行定义.

147 {
148 if (obstacle.IsVirtual() || !obstacle.IsStatic()) {
149 return true;
150 }
151
152 const auto &open_space_info = frame.open_space_info();
153 const auto &origin_point = open_space_info.origin_point();
154 const auto &origin_heading = open_space_info.origin_heading();
155 const auto &obstacle_box = obstacle.PerceptionBoundingBox();
156 auto obstacle_center_xy = obstacle_box.center();
157
158 // xy_boundary in xmin, xmax, ymin, ymax.
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]) {
163 return true;
164 }
165
166 // Translate the end pose back to world frame with endpose in x, y, phi, v
167 const auto &end_pose = open_space_info.open_space_end_pose();
168 Vec2d end_pose_x_y(end_pose[0], end_pose[1]);
169 end_pose_x_y.SelfRotate(origin_heading);
170 end_pose_x_y += origin_point;
171 const auto &vehicle_state = frame.vehicle_state();
172 // Get vehicle state
173 Vec2d vehicle_x_y(vehicle_state.x(), vehicle_state.y());
174
175 // Use vehicle position and end position to filter out obstacle
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) {
179 return true;
180 }
181 return false;
182}

◆ FormulateBoundaryConstraints()

bool apollo::planning::OpenSpaceRoiUtil::FormulateBoundaryConstraints ( OpenSpaceInfo *const  open_space_info)
static

main process to compute and load info needed by open space planner

在文件 open_space_roi_util.cc36 行定义.

36 {
37 auto &obstacles_vertices_vec = *open_space_info->mutable_obstacles_vertices_vec();
38 auto &obstacles_edges_num_vec = *open_space_info->mutable_obstacles_edges_num();
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;
44 }
45 open_space_info->set_obstacles_num(obstacles_vertices_vec.size());
46 // Transform vertices into the form of Ax>b
47 if (!LoadObstacleInHyperPlanes(open_space_info)) {
48 AERROR << "fail at LoadObstacleInHyperPlanes()";
49 return false;
50 }
51 return true;
52}
static bool LoadObstacleInHyperPlanes(OpenSpaceInfo *const open_space_info)
brief Transform the vertice presentation of the obstacles into linear inequality as Ax>b
#define AERROR
Definition log.h:44

◆ GetHyperPlanes()

bool apollo::planning::OpenSpaceRoiUtil::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 
)
static

在文件 open_space_roi_util.cc200 行定义.

205 {
206 if (obstacles_num != obstacles_vertices_vec.size()) {
207 AERROR << "obstacles_num != obstacles_vertices_vec.size()";
208 return false;
209 }
210
211 A_all->resize(obstacles_edges_num.sum(), 2);
212 b_all->resize(obstacles_edges_num.sum(), 1);
213
214 int counter = 0;
215 double kEpsilon = 1.0e-5;
216 // start building H representation
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);
221
222 // take two subsequent vertices, and computer hyperplane
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];
226
227 Eigen::MatrixXd A_tmp(2, 1), b_tmp(1, 1), ab(2, 1);
228 // find hyperplane passing through v1 and v2
229 if (std::abs(v1.x() - v2.x()) < kEpsilon) {
230 if (v2.y() < v1.y()) {
231 A_tmp << 1, 0;
232 b_tmp << v1.x();
233 } else {
234 A_tmp << -1, 0;
235 b_tmp << -v1.x();
236 }
237 } else if (std::abs(v1.y() - v2.y()) < kEpsilon) {
238 if (v1.x() < v2.x()) {
239 A_tmp << 0, 1;
240 b_tmp << v1.y();
241 } else {
242 A_tmp << 0, -1;
243 b_tmp << -v1.y();
244 }
245 } else {
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;
251 double a = ab(0, 0);
252 double b = ab(1, 0);
253
254 if (v1.x() < v2.x()) {
255 A_tmp << -a, 1;
256 b_tmp << b;
257 } else {
258 A_tmp << a, -1;
259 b_tmp << -b;
260 }
261 }
262
263 // store vertices
264 A_i.block(j, 0, 1, 2) = A_tmp.transpose();
265 b_i.block(j, 0, 1, 1) = b_tmp;
266 }
267
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);
271 }
272 return true;
273}

◆ GetRoiXYBoundary()

void apollo::planning::OpenSpaceRoiUtil::GetRoiXYBoundary ( const std::vector< std::vector< common::math::Vec2d > > &  roi_parking_boundary,
std::vector< double > *const  XYBoundary 
)
static

get XY boundary which is minmax x or y in roi boundary

参数
XYBoundaryx_min x_max y_min y_max
返回

在文件 open_space_roi_util.cc54 行定义.

56 {
57 XYBoundary->clear();
58 XYBoundary->resize(4); // x_min x_max y_min y_max
59 *XYBoundary
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());
70 }
71 }
72}

◆ IsPolygonClockwise()

bool apollo::planning::OpenSpaceRoiUtil::IsPolygonClockwise ( const std::vector< Vec2d > &  polygon)
static

在文件 open_space_roi_util.cc292 行定义.

292 {
293 double s = 0;
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();
297 } else {
298 s += polygon.at(i).x() * polygon.at(0).y() - polygon.at(i).y() * polygon.at(0).x();
299 }
300 }
301 if (s < 0) {
302 return true;
303 } else {
304 return false;
305 }
306}

◆ LoadObstacleInHyperPlanes()

bool apollo::planning::OpenSpaceRoiUtil::LoadObstacleInHyperPlanes ( OpenSpaceInfo *const  open_space_info)
static

brief Transform the vertice presentation of the obstacles into linear inequality as Ax>b

返回
true is success

在文件 open_space_roi_util.cc184 行定义.

184 {
185 *(open_space_info->mutable_obstacles_A()) = Eigen::MatrixXd::Zero(open_space_info->obstacles_edges_num().sum(), 2);
186 *(open_space_info->mutable_obstacles_b()) = Eigen::MatrixXd::Zero(open_space_info->obstacles_edges_num().sum(), 1);
187 // vertices using H-representation
188 if (!GetHyperPlanes(
189 open_space_info->obstacles_num(),
190 open_space_info->obstacles_edges_num(),
191 open_space_info->obstacles_vertices_vec(),
192 open_space_info->mutable_obstacles_A(),
193 open_space_info->mutable_obstacles_b())) {
194 AERROR << "Fail to present obstacle in hyperplane";
195 return false;
196 }
197 return true;
198}
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)

◆ LoadObstacles()

bool apollo::planning::OpenSpaceRoiUtil::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 
)
static

Load obstacle polygon to roi_boundary in clock wise order

参数
filtering_distancefilter out distance which is far away from adc
perception_obstacle_bufferadd extend buffer for obstacle box
roi_boundarythe roi polygon which adc can drive
返回
true is running success

在文件 open_space_roi_util.cc100 行定义.

105 {
106 auto obstacles_by_frame = frame->GetObstacleList();
107 size_t perception_obstacles_num = 0;
108 // load vertices for perception obstacles(repeat the first vertice at the
109 // last to form closed convex hull)
110 for (const auto &obstacle : obstacles_by_frame->Items()) {
111 if (FilterOutObstacle(filtering_distance, *frame, xy_boundary, *obstacle)) {
112 continue;
113 }
114 ++perception_obstacles_num;
115
116 Box2d original_box = obstacle->PerceptionBoundingBox();
117 original_box.LongitudinalExtend(perception_obstacle_buffer);
118 original_box.LateralExtend(perception_obstacle_buffer);
119
120 // TODO(Jinyun): Check correctness of ExpandByDistance() in polygon
121 // Polygon2d buffered_box(original_box);
122 // buffered_box = buffered_box.ExpandByDistance(
123 // config_.perception_obstacle_buffer());
124 // TODO(Runxin): Rotate from origin instead
125 // original_box.RotateFromCenter(-1.0 * origin_heading);
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();
132 }
133 // As the perception obstacle is a closed convex set, the first vertice
134 // is repeated at the end of the vector to help transform all four edges
135 // to inequality constraint
136 vertices_cw.push_back(vertices_cw.front());
137 roi_parking_boundary->push_back(vertices_cw);
138 }
139
140 return true;
141}
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

◆ TransformByOriginPoint() [1/4]

void apollo::planning::OpenSpaceRoiUtil::TransformByOriginPoint ( const common::math::Vec2d origin_point,
const double  heading,
common::math::Vec2d point 
)
static

在文件 open_space_roi_util.cc92 行定义.

95 {
96 *point -= origin_point;
97 point->SelfRotate(-heading);
98}

◆ TransformByOriginPoint() [2/4]

void apollo::planning::OpenSpaceRoiUtil::TransformByOriginPoint ( const common::math::Vec2d origin_point,
const double  heading,
std::vector< common::math::Vec2d > *  roi_parking_boundary 
)
static

在文件 open_space_roi_util.cc83 行定义.

86 {
87 for (auto &point : *roi_parking_boundary) {
88 TransformByOriginPoint(origin_point, heading, &point);
89 }
90}
static void TransformByOriginPoint(const common::math::Vec2d &origin_point, const double heading, std::vector< std::vector< common::math::Vec2d > > *roi_parking_boundary)

◆ TransformByOriginPoint() [3/4]

void apollo::planning::OpenSpaceRoiUtil::TransformByOriginPoint ( const common::math::Vec2d origin_point,
const double  heading,
std::vector< std::vector< common::math::Vec2d > > *  roi_parking_boundary 
)
static

在文件 open_space_roi_util.cc74 行定义.

77 {
78 for (auto &bound_vec : *roi_parking_boundary) {
79 TransformByOriginPoint(origin_point, heading, &bound_vec);
80 }
81}

◆ TransformByOriginPoint() [4/4]

void apollo::planning::OpenSpaceRoiUtil::TransformByOriginPoint ( const Vec2d origin_point,
const double &  origin_heading,
OpenSpaceInfo open_space_info 
)
static

在文件 open_space_roi_util.cc275 行定义.

278 {
279 open_space_info->set_origin_heading(origin_heading);
280 *open_space_info->mutable_origin_point() = origin_point;
281 auto obstacles_vertices_vec = open_space_info->mutable_obstacles_vertices_vec();
282 TransformByOriginPoint(origin_point, origin_heading, obstacles_vertices_vec);
283 auto end_pose_vec = open_space_info->mutable_open_space_end_pose();
284 Vec2d end_pose(end_pose_vec->at(0), end_pose_vec->at(1));
285 TransformByOriginPoint(origin_point, origin_heading, &end_pose);
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;
289 auto xy_boundary = open_space_info->mutable_ROI_xy_boundary();
290 GetRoiXYBoundary(*obstacles_vertices_vec, xy_boundary);
291}
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

◆ UpdateParkingPointsOrder()

bool apollo::planning::OpenSpaceRoiUtil::UpdateParkingPointsOrder ( const apollo::hdmap::Path nearby_path,
std::vector< Vec2d > *  points 
)
static

在文件 open_space_roi_util.cc319 行定义.

319 {
321 double min_dist = std::numeric_limits<double>::max();
322 size_t min_index = 0;
323 double sum_l = 0;
324 for (size_t i = 0; i < points->size(); i++) {
325 double s = 0.0, l = 0.0;
326 nearby_path.GetProjection(points->at(i), &s, &l);
327 sum_l += l;
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);
331 min_index = i;
332 }
333 }
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());
337 }
338 if (sum_l < 0) {
339 for (size_t i = 0; i < points->size(); i++) {
340 points->at(i) = tmp_points[i];
341 }
342 } else {
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];
346 }
347 }
348 return true;
349}
bool GetProjection(const common::math::Vec2d &point, double *accumulate_s, double *lateral) const
Definition path.cc:739
static bool AdjustPointsOrderToClockwise(std::vector< Vec2d > *polygon)

该类的文档由以下文件生成: