Apollo 11.0
自动驾驶开放平台
open_space_trajectory_optimizer_util.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
22
23namespace apollo {
24namespace planning {
25
26using common::math::Box2d;
27using common::math::Vec2d;
28
30 const Box2d& bounding_box,
31 const std::vector<std::vector<common::math::LineSegment2d>> obstacles_linesegments_vec) {
32 for (const auto& obstacle_linesegments : obstacles_linesegments_vec) {
33 for (const common::math::LineSegment2d& linesegment : obstacle_linesegments) {
34 if (bounding_box.HasOverlap(linesegment)) {
35 ADEBUG << "collision start at x: " << linesegment.start().x();
36 ADEBUG << "collision start at y: " << linesegment.start().y();
37 ADEBUG << "collision end at x: " << linesegment.end().x();
38 ADEBUG << "collision end at y: " << linesegment.end().y();
39 return true;
40 }
41 }
42 }
43 return false;
44}
45
47 const std::vector<std::vector<common::math::LineSegment2d>> obstacles_linesegments_vec,
48 const std::vector<std::pair<double, double>>& result,
49 std::vector<std::vector<Vec2d>>& box_vec) {
51 double shift_distance = vehicle_param.length() / 2.0 - vehicle_param.back_edge_to_center();
52 double init_length = vehicle_param.length();
53 double init_width = vehicle_param.width();
54 double rate = 1.0;
55
56 box_vec.clear();
57 for (int i = 0; i < result.size() - 1; i++) {
58 double x = result[i].first;
59 double y = result[i].second;
60 double x_next = result[i + 1].first;
61 double y_next = result[i + 1].second;
62 double heading = std::atan2(y_next - y, x_next - x);
63 AINFO << "init pos: " << x << " " << y;
64 // ego_box.Shift(shift_vec);
65 // x += shift_distance;
66 Box2d box({x, y}, heading, init_length, init_width);
67 for (int j = 1; j < 10; j++) {
68 if (OpenSpaceTrajectoryOptimizerUtil::BoxOverlapObstacles(box, obstacles_linesegments_vec))
69 break;
70 box = Box2d({x, y}, heading, init_length + j * 0.2, init_width + j * 0.2);
71 }
72 auto corners = box.GetAllCorners();
73 box_vec.push_back(corners);
74 // 3-----------2
75 // | |
76 // | |
77 // 4-----------1
78 ADEBUG << "corners 1: " << corners[0].x() << " " << corners[0].y();
79 ADEBUG << "corners 2: " << corners[1].x() << " " << corners[1].y();
80 ADEBUG << "corners 3: " << corners[2].x() << " " << corners[2].y();
81 ADEBUG << "corners 4: " << corners[3].x() << " " << corners[3].y();
82 }
83}
84
86 double rotate_angle,
87 const Vec2d& translate_origin,
88 double* x,
89 double* y,
90 double* phi) {
91 *x -= translate_origin.x();
92 *y -= translate_origin.y();
93 double tmp_x = *x;
94 *x = (*x) * std::cos(-rotate_angle) - (*y) * std::sin(-rotate_angle);
95 *y = tmp_x * std::sin(-rotate_angle) + (*y) * std::cos(-rotate_angle);
96 *phi = common::math::NormalizeAngle(*phi - rotate_angle);
97}
98
100 double rotate_angle,
101 const Vec2d& translate_origin,
102 double* x,
103 double* y,
104 double* phi) {
105 double tmp_x = *x;
106 *x = (*x) * std::cos(rotate_angle) - (*y) * std::sin(rotate_angle);
107 *y = tmp_x * std::sin(rotate_angle) + (*y) * std::cos(rotate_angle);
108 *x += translate_origin.x();
109 *y += translate_origin.y();
110 *phi = common::math::NormalizeAngle(*phi + rotate_angle);
111}
112
113} // namespace planning
114} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
void GetAllCorners(std::vector< Vec2d > *const corners) const
Getter of the corners of the box
Definition box2d.cc:140
bool HasOverlap(const LineSegment2d &line_segment) const
Determines whether this box overlaps a given line segment
Definition box2d.cc:184
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
static void PathPointNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
static bool BoxOverlapObstacles(const common::math::Box2d &bounding_box, const std::vector< std::vector< common::math::LineSegment2d > > obstacles_linesegments_vec)
check if box collision with obstacles
static void PathPointDeNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
static void GeneratePointBox(const std::vector< std::vector< common::math::LineSegment2d > > obstacles_linesegments_vec, const std::vector< std::pair< double, double > > &result, std::vector< std::vector< common::math::Vec2d > > &box_vec)
check if box collision with obstacles
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param