Apollo 11.0
自动驾驶开放平台
node3d.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
17/*
18 * @file
19 */
20
22
23#include "absl/strings/str_cat.h"
24
25#include "cyber/common/log.h"
26
27namespace apollo {
28namespace planning {
29
31
32Node3d::Node3d(double x, double y, double phi) {
33 x_ = x;
34 y_ = y;
35 phi_ = phi;
36}
37
39 double x,
40 double y,
41 double phi,
42 const std::vector<double>& XYbounds,
43 const PlannerOpenSpaceConfig& open_space_conf) {
44 CHECK_EQ(XYbounds.size(), 4U) << "XYbounds size is not 4, but" << XYbounds.size();
45
46 x_ = x;
47 y_ = y;
48 phi_ = phi;
49
50 x_grid_ = static_cast<int>((x_ - XYbounds[0]) / open_space_conf.warm_start_config().xy_grid_resolution());
51 y_grid_ = static_cast<int>((y_ - XYbounds[2]) / open_space_conf.warm_start_config().xy_grid_resolution());
52 phi_grid_ = static_cast<int>((phi_ - (-M_PI)) / open_space_conf.warm_start_config().phi_grid_resolution());
53
54 traversed_x_.push_back(x);
55 traversed_y_.push_back(y);
56 traversed_phi_.push_back(phi);
57
58 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
59}
60
62 const std::vector<double>& traversed_x,
63 const std::vector<double>& traversed_y,
64 const std::vector<double>& traversed_phi,
65 const std::vector<double>& XYbounds,
66 const PlannerOpenSpaceConfig& open_space_conf) {
67 CHECK_EQ(XYbounds.size(), 4U) << "XYbounds size is not 4, but" << XYbounds.size();
68 CHECK_EQ(traversed_x.size(), traversed_y.size());
69 CHECK_EQ(traversed_x.size(), traversed_phi.size());
70
71 x_ = traversed_x.back();
72 y_ = traversed_y.back();
73 phi_ = traversed_phi.back();
74
75 // XYbounds in xmin, xmax, ymin, ymax
76 x_grid_ = static_cast<int>((x_ - XYbounds[0]) / open_space_conf.warm_start_config().xy_grid_resolution());
77 y_grid_ = static_cast<int>((y_ - XYbounds[2]) / open_space_conf.warm_start_config().xy_grid_resolution());
78 phi_grid_ = static_cast<int>((phi_ - (-M_PI)) / open_space_conf.warm_start_config().phi_grid_resolution());
79
80 traversed_x_ = traversed_x;
81 traversed_y_ = traversed_y;
82 traversed_phi_ = traversed_phi;
83
84 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
85 step_size_ = traversed_x.size();
86}
87
89 double x,
90 double y,
91 double phi,
92 const std::vector<double>& XYbounds,
93 const WarmStartConfig& warm_start_conf) {
94 CHECK_EQ(XYbounds.size(), 4U) << "XYbounds size is not 4, but" << XYbounds.size();
95
96 x_ = x;
97 y_ = y;
98 phi_ = phi;
99
100 x_grid_ = static_cast<int>((x_ - XYbounds[0]) / warm_start_conf.xy_grid_resolution());
101 y_grid_ = static_cast<int>((y_ - XYbounds[2]) / warm_start_conf.xy_grid_resolution());
102 phi_grid_ = static_cast<int>((phi_ - (-M_PI)) / warm_start_conf.phi_grid_resolution());
103
104 traversed_x_.push_back(x);
105 traversed_y_.push_back(y);
106 traversed_phi_.push_back(phi);
107
108 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
109}
110
112 const std::vector<double>& traversed_x,
113 const std::vector<double>& traversed_y,
114 const std::vector<double>& traversed_phi,
115 const std::vector<double>& XYbounds,
116 const WarmStartConfig& warm_start_conf) {
117 CHECK_EQ(XYbounds.size(), 4U) << "XYbounds size is not 4, but" << XYbounds.size();
118 CHECK_EQ(traversed_x.size(), traversed_y.size());
119 CHECK_EQ(traversed_x.size(), traversed_phi.size());
120
121 x_ = traversed_x.back();
122 y_ = traversed_y.back();
123 phi_ = traversed_phi.back();
124
125 // XYbounds in xmin, xmax, ymin, ymax
126 x_grid_ = static_cast<int>((x_ - XYbounds[0]) / warm_start_conf.xy_grid_resolution());
127 y_grid_ = static_cast<int>((y_ - XYbounds[2]) / warm_start_conf.xy_grid_resolution());
128 phi_grid_ = static_cast<int>((phi_ - (-M_PI)) / warm_start_conf.phi_grid_resolution());
129
130 traversed_x_ = traversed_x;
131 traversed_y_ = traversed_y;
132 traversed_phi_ = traversed_phi;
133
134 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
135 step_size_ = traversed_x.size();
136}
137
139 const common::VehicleParam& vehicle_param_,
140 const double x,
141 const double y,
142 const double phi) {
143 double ego_length = vehicle_param_.length();
144 double ego_width = vehicle_param_.width();
145 double shift_distance = ego_length / 2.0 - vehicle_param_.back_edge_to_center();
146 Box2d ego_box({x + shift_distance * std::cos(phi), y + shift_distance * std::sin(phi)}, phi, ego_length, ego_width);
147 return ego_box;
148}
149
150bool Node3d::operator==(const Node3d& right) const {
151 return right.GetIndex() == index_;
152}
153
154std::string Node3d::ComputeStringIndex(int x_grid, int y_grid, int phi_grid) {
155 return absl::StrCat(x_grid, "_", y_grid, "_", phi_grid);
156}
157
158} // namespace planning
159} // namespace apollo
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
bool operator==(const Node3d &right) const
Definition node3d.cc:150
const std::string & GetIndex() const
Definition node3d.h:79
static apollo::common::math::Box2d GetBoundingBox(const common::VehicleParam &vehicle_param_, const double x, const double y, const double phi)
Definition node3d.cc:138
Node3d(const double x, const double y, const double phi)
Definition node3d.cc:32
Planning module main class.
class register implement
Definition arena_queue.h:37