Apollo 10.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
38Node3d::Node3d(double x, double y, double phi,
39 const std::vector<double>& XYbounds,
40 const PlannerOpenSpaceConfig& open_space_conf) {
41 CHECK_EQ(XYbounds.size(), 4U)
42 << "XYbounds size is not 4, but" << XYbounds.size();
43
44 x_ = x;
45 y_ = y;
46 phi_ = phi;
47
48 x_grid_ = static_cast<int>(
49 (x_ - XYbounds[0]) /
50 open_space_conf.warm_start_config().xy_grid_resolution());
51 y_grid_ = static_cast<int>(
52 (y_ - XYbounds[2]) /
53 open_space_conf.warm_start_config().xy_grid_resolution());
54 phi_grid_ = static_cast<int>(
55 (phi_ - (-M_PI)) /
56 open_space_conf.warm_start_config().phi_grid_resolution());
57
58 traversed_x_.push_back(x);
59 traversed_y_.push_back(y);
60 traversed_phi_.push_back(phi);
61
62 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
63}
64
65Node3d::Node3d(const std::vector<double>& traversed_x,
66 const std::vector<double>& traversed_y,
67 const std::vector<double>& traversed_phi,
68 const std::vector<double>& XYbounds,
69 const PlannerOpenSpaceConfig& open_space_conf) {
70 CHECK_EQ(XYbounds.size(), 4U)
71 << "XYbounds size is not 4, but" << XYbounds.size();
72 CHECK_EQ(traversed_x.size(), traversed_y.size());
73 CHECK_EQ(traversed_x.size(), traversed_phi.size());
74
75 x_ = traversed_x.back();
76 y_ = traversed_y.back();
77 phi_ = traversed_phi.back();
78
79 // XYbounds in xmin, xmax, ymin, ymax
80 x_grid_ = static_cast<int>(
81 (x_ - XYbounds[0]) /
82 open_space_conf.warm_start_config().xy_grid_resolution());
83 y_grid_ = static_cast<int>(
84 (y_ - XYbounds[2]) /
85 open_space_conf.warm_start_config().xy_grid_resolution());
86 phi_grid_ = static_cast<int>(
87 (phi_ - (-M_PI)) /
88 open_space_conf.warm_start_config().phi_grid_resolution());
89
90 traversed_x_ = traversed_x;
91 traversed_y_ = traversed_y;
92 traversed_phi_ = traversed_phi;
93
94 index_ = ComputeStringIndex(x_grid_, y_grid_, phi_grid_);
95 step_size_ = traversed_x.size();
96}
97
99 const double x, const double y, const double phi) {
100 double ego_length = vehicle_param_.length();
101 double ego_width = vehicle_param_.width();
102 double shift_distance =
103 ego_length / 2.0 - vehicle_param_.back_edge_to_center();
104 Box2d ego_box(
105 {x + shift_distance * std::cos(phi), y + shift_distance * std::sin(phi)},
106 phi, ego_length, ego_width);
107 return ego_box;
108}
109
110bool Node3d::operator==(const Node3d& right) const {
111 return right.GetIndex() == index_;
112}
113
114std::string Node3d::ComputeStringIndex(int x_grid, int y_grid, int phi_grid) {
115 return absl::StrCat(x_grid, "_", y_grid, "_", phi_grid);
116}
117
118} // namespace planning
119} // namespace apollo
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
bool operator==(const Node3d &right) const
Definition node3d.cc:110
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:98
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