Apollo 10.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>>
32 obstacles_linesegments_vec) {
33 for (const auto& obstacle_linesegments : obstacles_linesegments_vec) {
34 for (const common::math::LineSegment2d& linesegment :
35 obstacle_linesegments) {
36 if (bounding_box.HasOverlap(linesegment)) {
37 ADEBUG << "collision start at x: " << linesegment.start().x();
38 ADEBUG << "collision start at y: " << linesegment.start().y();
39 ADEBUG << "collision end at x: " << linesegment.end().x();
40 ADEBUG << "collision end at y: " << linesegment.end().y();
41 return true;
42 }
43 }
44 }
45 return false;
46}
47
49 const std::vector<std::vector<common::math::LineSegment2d>>
50 obstacles_linesegments_vec,
51 const std::vector<std::pair<double, double>>& result,
52 std::vector<std::vector<Vec2d>>& box_vec) {
54 double shift_distance = vehicle_param.length() / 2.0 -
55 vehicle_param.back_edge_to_center();
56 double init_length = vehicle_param.length();
57 double init_width = vehicle_param.width();
58 double rate = 1.0;
59
60 box_vec.clear();
61 for (int i = 0; i < result.size() - 1; i++) {
62 double x = result[i].first;
63 double y = result[i].second;
64 double x_next = result[i + 1].first;
65 double y_next = result[i + 1].second;
66 double heading = std::atan2(y_next - y, x_next - x);
67 AINFO << "init pos: " << x << " " << y;
68 // ego_box.Shift(shift_vec);
69 // x += shift_distance;
70 Box2d box({x, y}, heading, init_length, init_width);
71 for (int j = 1; j < 10; j++) {
73 box, obstacles_linesegments_vec))
74 break;
75 box = Box2d({x, y}, heading, init_length + j * 0.2, init_width + j * 0.2);
76 }
77 auto corners = box.GetAllCorners();
78 box_vec.push_back(corners);
79 // 3-----------2
80 // | |
81 // | |
82 // 4-----------1
83 ADEBUG << "corners 1: " << corners[0].x() << " " << corners[0].y();
84 ADEBUG << "corners 2: " << corners[1].x() << " " << corners[1].y();
85 ADEBUG << "corners 3: " << corners[2].x() << " " << corners[2].y();
86 ADEBUG << "corners 4: " << corners[3].x() << " " << corners[3].y();
87 }
88}
89
91 double rotate_angle,
92 const Vec2d& translate_origin,
93 double* x,
94 double* y,
95 double* phi) {
96 *x -= translate_origin.x();
97 *y -= translate_origin.y();
98 double tmp_x = *x;
99 *x = (*x) * std::cos(-rotate_angle) - (*y) * std::sin(-rotate_angle);
100 *y = tmp_x * std::sin(-rotate_angle) + (*y) * std::cos(-rotate_angle);
101 *phi = common::math::NormalizeAngle(*phi - rotate_angle);
102}
103
105 double rotate_angle,
106 const Vec2d& translate_origin,
107 double* x,
108 double* y,
109 double* phi) {
110 double tmp_x = *x;
111 *x = (*x) * std::cos(rotate_angle) - (*y) * std::sin(rotate_angle);
112 *y = tmp_x * std::sin(rotate_angle) + (*y) * std::cos(rotate_angle);
113 *x += translate_origin.x();
114 *y += translate_origin.y();
115 *phi = common::math::NormalizeAngle(*phi + rotate_angle);
116}
117
118} // namespace planning
119} // 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