Apollo 11.0
自动驾驶开放平台
path_generation.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
21
22#include <string>
23#include <utility>
24#include <vector>
25
27
28namespace apollo {
29namespace planning {
30
32 Frame* frame, ReferenceLineInfo* reference_line_info) {
33 Task::Execute(frame, reference_line_info);
34 return Process(frame, reference_line_info);
35}
36
41
43 const PathBound& path_boundaries, const std::string& debug_name,
44 ReferenceLineInfo* const reference_line_info) {
45 // Sanity checks.
46 if (path_boundaries.empty()) {
47 AINFO << "path boundary is empty!";
48 return;
49 }
50 CHECK_NOTNULL(reference_line_info);
51
52 // Take the left and right path boundaries, and transform them into two
53 // PathData so that they can be displayed in simulator.
54 std::vector<common::FrenetFramePoint> frenet_frame_left_boundaries;
55 std::vector<common::FrenetFramePoint> frenet_frame_right_boundaries;
56 for (const PathBoundPoint& path_bound_point : path_boundaries) {
57 common::FrenetFramePoint frenet_frame_point;
58 frenet_frame_point.set_s(path_bound_point.s);
59 frenet_frame_point.set_dl(0.0);
60 frenet_frame_point.set_ddl(0.0);
61
62 frenet_frame_point.set_l(path_bound_point.l_lower.l);
63 frenet_frame_right_boundaries.push_back(frenet_frame_point);
64 frenet_frame_point.set_l(path_bound_point.l_upper.l);
65 frenet_frame_left_boundaries.push_back(frenet_frame_point);
66 }
67
68 auto frenet_frame_left_path =
69 FrenetFramePath(std::move(frenet_frame_left_boundaries));
70 auto frenet_frame_right_path =
71 FrenetFramePath(std::move(frenet_frame_right_boundaries));
72
73 PathData left_path_data;
74 left_path_data.SetReferenceLine(&(reference_line_info->reference_line()));
75 left_path_data.SetFrenetPath(std::move(frenet_frame_left_path));
76 PathData right_path_data;
77 right_path_data.SetReferenceLine(&(reference_line_info->reference_line()));
78 right_path_data.SetFrenetPath(std::move(frenet_frame_right_path));
79
80 // Insert the transformed PathData into the simulator display.
81 auto* ptr_display_path_1 =
82 reference_line_info->mutable_debug()->mutable_planning_data()->add_path();
83 ptr_display_path_1->set_name(std::string("planning_path_boundary_1_") +
84 debug_name);
85 ptr_display_path_1->mutable_path_point()->CopyFrom(
86 {left_path_data.discretized_path().begin(),
87 left_path_data.discretized_path().end()});
88 auto* ptr_display_path_2 =
89 reference_line_info->mutable_debug()->mutable_planning_data()->add_path();
90 ptr_display_path_2->set_name(std::string("planning_path_boundary_2_") +
91 debug_name);
92 ptr_display_path_2->mutable_path_point()->CopyFrom(
93 {right_path_data.discretized_path().begin(),
94 right_path_data.discretized_path().end()});
95}
96
98 const PathData& path_data, const std::string& debug_name,
99 ReferenceLineInfo* const reference_line_info) {
100 const auto& path_points = path_data.discretized_path();
101 auto* ptr_optimized_path =
102 reference_line_info->mutable_debug()->mutable_planning_data()->add_path();
103 ptr_optimized_path->set_name(std::string("candidate_path_") + debug_name);
104 ptr_optimized_path->mutable_path_point()->CopyFrom(
105 {path_points.begin(), path_points.end()});
106}
108 const ReferenceLine& reference_line = reference_line_info_->reference_line();
109 common::TrajectoryPoint planning_start_point = frame_->PlanningStartPoint();
110 if (FLAGS_use_front_axe_center_in_path_planning) {
111 double front_to_rear_axe_distance =
114 .wheel_base();
115 planning_start_point.mutable_path_point()->set_x(
116 planning_start_point.path_point().x() +
117 front_to_rear_axe_distance *
118 std::cos(planning_start_point.path_point().theta()));
119 planning_start_point.mutable_path_point()->set_y(
120 planning_start_point.path_point().y() +
121 front_to_rear_axe_distance *
122 std::sin(planning_start_point.path_point().theta()));
123 }
124 AINFO << std::fixed << "Plan at the starting point: x = "
125 << planning_start_point.path_point().x()
126 << ", y = " << planning_start_point.path_point().y()
127 << ", and angle = " << planning_start_point.path_point().theta();
128
129 // Initialize some private variables.
130 // ADC s/l info.
131 init_sl_state_ = reference_line.ToFrenetFrame(planning_start_point);
132}
133
134bool PathGeneration::GetSLBoundary(const PathData& path_data, int point_index,
135 const ReferenceLineInfo* reference_line_info,
136 SLBoundary* const sl_boundary) {
137 CHECK_NOTNULL(sl_boundary);
138 const auto& discrete_path = path_data.discretized_path();
139 if (point_index < 0 ||
140 static_cast<size_t>(point_index) > discrete_path.size()) {
141 return false;
142 }
143 sl_boundary->mutable_boundary_point()->Clear();
144 // Get vehicle config parameters.
145 const auto& vehicle_config =
146 common::VehicleConfigHelper::Instance()->GetConfig();
147 const double ego_length = vehicle_config.vehicle_param().length();
148 const double ego_width = vehicle_config.vehicle_param().width();
149 const double ego_back_to_center =
150 vehicle_config.vehicle_param().back_edge_to_center();
151 const double ego_center_shift_distance =
152 ego_length / 2.0 - ego_back_to_center;
153 // Generate vehicle bounding box.
154 const auto& rear_center_path_point = discrete_path[point_index];
155 const double ego_theta = rear_center_path_point.theta();
156 common::math::Box2d ego_box(
157 {rear_center_path_point.x(), rear_center_path_point.y()}, ego_theta,
158 ego_length, ego_width);
159 common::math::Vec2d shift_vec{
160 ego_center_shift_distance * ego_box.cos_heading(),
161 ego_center_shift_distance * ego_box.sin_heading()};
162 ego_box.Shift(shift_vec);
163 // Set warm_start_s near the geometry center of the box.
164 double warm_start_s = path_data.frenet_frame_path()[point_index].s() +
165 ego_center_shift_distance;
166 // Get the SL boundary of vehicle.
167 reference_line_info->reference_line().GetSLBoundary(ego_box, sl_boundary,
168 warm_start_s);
169 return true;
170}
171
172} // namespace planning
173} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
Frame holds all data for one planning cycle.
Definition frame.h:62
const common::TrajectoryPoint & PlanningStartPoint() const
Definition frame.cc:79
void SetReferenceLine(const ReferenceLine *reference_line)
Definition path_data.cc:107
const FrenetFramePath & frenet_frame_path() const
Definition path_data.cc:94
const DiscretizedPath & discretized_path() const
Definition path_data.cc:90
bool SetFrenetPath(FrenetFramePath frenet_path)
Definition path_data.cc:58
void RecordDebugInfo(const PathBound &path_boundaries, const std::string &debug_name, ReferenceLineInfo *const reference_line_info)
add path_boundary debug info for PnC monitor
apollo::common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info) override
bool GetSLBoundary(const PathData &path_data, int point_index, const ReferenceLineInfo *reference_line_info, SLBoundary *const sl_boundary)
get sl boundary of the point on PathData
virtual apollo::common::Status Process(Frame *frame, ReferenceLineInfo *reference_line_info)
void GetStartPointSLState()
calculate init sl state by planning start point, result will store in init_sl_state_
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
planning_internal::Debug * mutable_debug()
std::pair< std::array< double, 3 >, std::array< double, 3 > > ToFrenetFrame(const common::TrajectoryPoint &traj_point) const
bool GetSLBoundary(const common::math::Box2d &box, SLBoundary *const sl_boundary, double warm_start_s=-1.0) const
Get the SL Boundary of the box.
ReferenceLineInfo * reference_line_info_
Definition task.h:58
virtual common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info)
Definition task.cc:60
Planning module main class.
#define AINFO
Definition log.h:42
std::vector< PathBoundPoint > PathBound
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param