Apollo 11.0
自动驾驶开放平台
fallback_path.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
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
27
28namespace apollo {
29namespace planning {
30
33
34bool FallbackPath::Init(const std::string& config_dir, const std::string& name,
35 const std::shared_ptr<DependencyInjector>& injector) {
36 if (!Task::Init(config_dir, name, injector)) {
37 return false;
38 }
39 // Load the config this task.
40 return Task::LoadConfig<FallbackPathConfig>(&config_);
41}
42
43apollo::common::Status FallbackPath::Process(
44 Frame* frame, ReferenceLineInfo* reference_line_info) {
45 if (!reference_line_info->path_data().Empty() ||
46 reference_line_info->IsChangeLanePath()) {
47 return Status::OK();
48 }
49 std::vector<PathBoundary> candidate_path_boundaries;
50 std::vector<PathData> candidate_path_data;
51
53 if (!DecidePathBounds(&candidate_path_boundaries)) {
54 return Status::OK();
55 }
56 if (!OptimizePath(candidate_path_boundaries, &candidate_path_data)) {
57 return Status::OK();
58 }
59 if (!AssessPath(&candidate_path_data,
60 reference_line_info->mutable_path_data())) {
61 AERROR << "Path assessment failed";
62 }
63
64 return Status::OK();
65}
66
67bool FallbackPath::DecidePathBounds(std::vector<PathBoundary>* boundary) {
68 boundary->emplace_back();
69 auto& path_bound = boundary->back();
70 // 1. Initialize the path boundaries to be an indefinitely large area.
72 &path_bound, init_sl_state_)) {
73 const std::string msg = "Failed to initialize path boundaries.";
74 AERROR << msg;
75 return false;
76 }
77 // 2. Decide a rough boundary based on lane info and ADC's position
79 *reference_line_info_, init_sl_state_, &path_bound)) {
80 AERROR << "Failed to decide a rough boundary based on self lane.";
81 return false;
82 }
85 &path_bound)) {
86 AERROR << "Failed to decide a rough boundary based on adc.";
87 return false;
88 }
89 path_bound.set_label(absl::StrCat("fallback/", "self"));
90 RecordDebugInfo(path_bound, path_bound.label(), reference_line_info_);
91 return true;
92}
93
94bool FallbackPath::OptimizePath(
95 const std::vector<PathBoundary>& path_boundaries,
96 std::vector<PathData>* candidate_path_data) {
97 const auto& config = config_.path_optimizer_config();
98 const ReferenceLine& reference_line = reference_line_info_->reference_line();
99 std::array<double, 3> end_state = {0.0, 0.0, 0.0};
100 for (const auto& path_boundary : path_boundaries) {
101 size_t path_boundary_size = path_boundary.boundary().size();
102 if (path_boundary_size <= 1U) {
103 AERROR << "Get invalid path boundary with size: " << path_boundary_size;
104 return false;
105 }
106 std::vector<double> opt_l, opt_dl, opt_ddl;
107 std::vector<std::pair<double, double>> ddl_bounds;
108 PathOptimizerUtil::CalculateAccBound(path_boundary, reference_line,
109 &ddl_bounds);
110 const double jerk_bound = PathOptimizerUtil::EstimateJerkBoundary(
111 std::fmax(init_sl_state_.first[1], 1e-12));
112 std::vector<double> ref_l(path_boundary_size, 0);
113 std::vector<double> weight_ref_l(path_boundary_size,
114 config.path_reference_l_weight());
115 bool res_opt = PathOptimizerUtil::OptimizePath(
116 init_sl_state_, end_state, ref_l, weight_ref_l, path_boundary,
117 ddl_bounds, jerk_bound, config, &opt_l, &opt_dl, &opt_ddl);
118 if (res_opt) {
119 auto frenet_frame_path = PathOptimizerUtil::ToPiecewiseJerkPath(
120 opt_l, opt_dl, opt_ddl, path_boundary.delta_s(),
121 path_boundary.start_s());
122 PathData path_data;
123 path_data.SetReferenceLine(&reference_line);
124 path_data.SetFrenetPath(std::move(frenet_frame_path));
125 if (FLAGS_use_front_axe_center_in_path_planning) {
126 auto discretized_path = DiscretizedPath(
128 path_data));
129 path_data.SetDiscretizedPath(discretized_path);
130 }
131 path_data.set_path_label(path_boundary.label());
132 path_data.set_blocking_obstacle_id(path_boundary.blocking_obstacle_id());
133 candidate_path_data->push_back(std::move(path_data));
134 }
135 }
136 if (candidate_path_data->empty()) {
137 return false;
138 }
139 return true;
140}
141
142bool FallbackPath::AssessPath(std::vector<PathData>* candidate_path_data,
143 PathData* final_path) {
144 PathData curr_path_data = candidate_path_data->back();
145 RecordDebugInfo(curr_path_data, curr_path_data.path_label(),
147 if (curr_path_data.Empty()) {
148 ADEBUG << "Fallback Path: path data is empty.";
149 return false;
150 }
151 // Check if the path is greatly off the reference line.
153 ADEBUG << "Fallback Path: ADC is greatly off reference line.";
154 return false;
155 }
156 // Check if the path is greatly off the road.
158 curr_path_data)) {
159 ADEBUG << "Fallback Path: ADC is greatly off road.";
160 return false;
161 }
162
163 if (curr_path_data.Empty()) {
164 AINFO << "Lane follow path is empty after trimed";
165 return false;
166 }
167 *final_path = curr_path_data;
168 return true;
169}
170
171} // namespace planning
172} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
@Brief This is a helper class that can load vehicle configurations.
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
Frame holds all data for one planning cycle.
Definition frame.h:62
static bool IsGreatlyOffReferenceLine(const PathData &path_data)
static bool IsGreatlyOffRoad(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
static bool GetBoundaryFromSelfLane(const ReferenceLineInfo &reference_line_info, const SLState &init_sl_state, PathBoundary *const path_bound)
generate path bound by self lane and adc position
static bool ExtendBoundaryByADC(const ReferenceLineInfo &reference_line_info, const SLState &init_sl_state, const double extend_buffer, PathBoundary *const path_bound)
extend boundary to include adc
static bool InitPathBoundary(const ReferenceLineInfo &reference_line_info, PathBoundary *const path_bound, SLState init_sl_state)
Starting from ADC's current position, increment until the path length, and set lateral bounds to be i...
void RecordDebugInfo(const PathBound &path_boundaries, const std::string &debug_name, ReferenceLineInfo *const reference_line_info)
add path_boundary debug info for PnC monitor
void GetStartPointSLState()
calculate init sl state by planning start point, result will store in init_sl_state_
static std::vector< common::PathPoint > ConvertPathPointRefFromFrontAxeToRearAxe(const PathData &path_data)
static void CalculateAccBound(const PathBoundary &path_boundary, const ReferenceLine &reference_line, std::vector< std::pair< double, double > > *ddl_bounds)
calculate ddl bound by referenceline kappa and adc lat accleration
static FrenetFramePath ToPiecewiseJerkPath(const std::vector< double > &x, const std::vector< double > &dx, const std::vector< double > &ddx, const double delta_s, const double start_s)
Data format tramform from raw data to FrenetFramePath
static double EstimateJerkBoundary(const double vehicle_speed)
Calculation of jerk boundary based on vehicle kinematics model.
static bool OptimizePath(const SLState &init_state, const std::array< double, 3 > &end_state, std::vector< double > l_ref, std::vector< double > l_ref_weight, const PathBoundary &path_boundary, const std::vector< std::pair< double, double > > &ddl_bounds, double dddl_bound, const PiecewiseJerkPathConfig &config, std::vector< double > *x, std::vector< double > *dx, std::vector< double > *ddx)
Piecewise jerk path optimizer.
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
bool IsChangeLanePath() const
Check if the current reference line is a change lane reference line, i.e., ADC's current position is ...
ReferenceLineInfo * reference_line_info_
Definition task.h:58
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Definition task.cc:40
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
optional PiecewiseJerkPathConfig path_optimizer_config