Apollo 11.0
自动驾驶开放平台
speed_bounds_decider.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
19#include <algorithm>
20#include <limits>
21#include <memory>
22#include <string>
23#include <vector>
24
33
34namespace apollo {
35namespace planning {
36
42
44 const std::string &config_dir, const std::string &name,
45 const std::shared_ptr<DependencyInjector> &injector) {
46 if (!Decider::Init(config_dir, name, injector)) {
47 return false;
48 }
49 // Load the config this task.
50 return Decider::LoadConfig<SpeedBoundsDeciderConfig>(&config_);
51}
52
53Status SpeedBoundsDecider::Process(
54 Frame *const frame, ReferenceLineInfo *const reference_line_info) {
55 // retrieve data from frame and reference_line_info
56 const PathData &path_data = reference_line_info->path_data();
57 const TrajectoryPoint &init_point = frame->PlanningStartPoint();
58 const ReferenceLine &reference_line = reference_line_info->reference_line();
59 PathDecision *const path_decision = reference_line_info->path_decision();
60
61 // 1. Map obstacles into st graph
62 auto time1 = std::chrono::system_clock::now();
63 STBoundaryMapper boundary_mapper(config_, reference_line, path_data,
64 path_data.discretized_path().Length(),
65 config_.total_time(), injector_);
66
67 if (!FLAGS_use_st_drivable_boundary) {
68 path_decision->EraseStBoundaries();
69 }
70
71 if (boundary_mapper.ComputeSTBoundary(path_decision).code() ==
72 ErrorCode::PLANNING_ERROR) {
73 const std::string msg = "Mapping obstacle failed.";
74 AERROR << msg;
75 return Status(ErrorCode::PLANNING_ERROR, msg);
76 }
77 auto time2 = std::chrono::system_clock::now();
78 std::chrono::duration<double> diff = time2 - time1;
79 ADEBUG << "Time for ST Boundary Mapping = " << diff.count() * 1000
80 << " msec.";
81
82 std::vector<const STBoundary *> boundaries;
83 for (auto *obstacle : path_decision->obstacles().Items()) {
84 const auto &id = obstacle->Id();
85 const auto &st_boundary = obstacle->path_st_boundary();
86 if (!st_boundary.IsEmpty()) {
87 if (st_boundary.boundary_type() == STBoundary::BoundaryType::KEEP_CLEAR) {
88 path_decision->Find(id)->SetBlockingObstacle(false);
89 } else {
90 path_decision->Find(id)->SetBlockingObstacle(true);
91 }
92 st_boundary.PrintDebug("_obs_st_bounds");
93 boundaries.push_back(&st_boundary);
94 }
95 }
96
97 const double min_s_on_st_boundaries = SetSpeedFallbackDistance(path_decision);
98
99 // 2. Create speed limit along path
100 SpeedLimitDecider speed_limit_decider(config_, reference_line, path_data);
101
102 SpeedLimit speed_limit;
103 if (!speed_limit_decider
104 .GetSpeedLimits(path_decision->obstacles(), &speed_limit)
105 .ok()) {
106 const std::string msg = "Getting speed limits failed!";
107 AERROR << msg;
108 return Status(ErrorCode::PLANNING_ERROR, msg);
109 }
110
111 // 3. Get path_length as s axis search bound in st graph
112 const double path_data_length = path_data.discretized_path().Length();
113
114 // 4. Get time duration as t axis search bound in st graph
115 const double total_time_by_conf = config_.total_time();
116
117 // Load generated st graph data back to frame
118 StGraphData *st_graph_data = reference_line_info_->mutable_st_graph_data();
119
120 // Add a st_graph debug info and save the pointer to st_graph_data for
121 // optimizer logging
122 auto *debug = reference_line_info_->mutable_debug();
123 STGraphDebug *st_graph_debug = debug->mutable_planning_data()->add_st_graph();
124
125 st_graph_data->LoadData(boundaries, min_s_on_st_boundaries, init_point,
126 speed_limit, reference_line_info->GetCruiseSpeed(),
127 path_data_length, total_time_by_conf, st_graph_debug);
128
129 // Create and record st_graph debug info
130 RecordSTGraphDebug(*st_graph_data, st_graph_debug);
131
132 return Status::OK();
133}
134
135double SpeedBoundsDecider::SetSpeedFallbackDistance(
136 PathDecision *const path_decision) {
137 // Set min_s_on_st_boundaries to guide speed fallback.
138 static constexpr double kEpsilon = 1.0e-6;
139 double min_s_non_reverse = std::numeric_limits<double>::infinity();
140 double min_s_reverse = std::numeric_limits<double>::infinity();
141
142 for (auto *obstacle : path_decision->obstacles().Items()) {
143 const auto &st_boundary = obstacle->path_st_boundary();
144
145 if (st_boundary.IsEmpty()) {
146 continue;
147 }
148
149 const auto left_bottom_point_s = st_boundary.bottom_left_point().s();
150 const auto right_bottom_point_s = st_boundary.bottom_right_point().s();
151 const auto lowest_s = std::min(left_bottom_point_s, right_bottom_point_s);
152
153 if (left_bottom_point_s - right_bottom_point_s > kEpsilon) {
154 if (min_s_reverse > lowest_s) {
155 min_s_reverse = lowest_s;
156 }
157 } else if (min_s_non_reverse > lowest_s) {
158 min_s_non_reverse = lowest_s;
159 }
160 }
161
162 min_s_reverse = std::max(min_s_reverse, 0.0);
163 min_s_non_reverse = std::max(min_s_non_reverse, 0.0);
164
165 return min_s_non_reverse > min_s_reverse ? 0.0 : min_s_non_reverse;
166}
167
168void SpeedBoundsDecider::RecordSTGraphDebug(
169 const StGraphData &st_graph_data, STGraphDebug *st_graph_debug) const {
170 if (!FLAGS_enable_record_debug || !st_graph_debug) {
171 ADEBUG << "Skip record debug info";
172 return;
173 }
174
175 for (const auto &boundary : st_graph_data.st_boundaries()) {
176 auto boundary_debug = st_graph_debug->add_boundary();
177 boundary_debug->set_name(boundary->id());
178 switch (boundary->boundary_type()) {
180 boundary_debug->set_type(StGraphBoundaryDebug::ST_BOUNDARY_TYPE_FOLLOW);
181 break;
183 boundary_debug->set_type(
185 break;
187 boundary_debug->set_type(StGraphBoundaryDebug::ST_BOUNDARY_TYPE_STOP);
188 break;
190 boundary_debug->set_type(
192 break;
194 boundary_debug->set_type(StGraphBoundaryDebug::ST_BOUNDARY_TYPE_YIELD);
195 break;
197 boundary_debug->set_type(
199 break;
200 }
201
202 for (const auto &point : boundary->points()) {
203 auto point_debug = boundary_debug->add_point();
204 point_debug->set_t(point.x());
205 point_debug->set_s(point.y());
206 }
207 }
208
209 for (const auto &point : st_graph_data.speed_limit().speed_limit_points()) {
210 common::SpeedPoint *speed_point = st_graph_debug->add_speed_limit();
211 speed_point->set_s(point.first);
212 speed_point->set_v(point.second);
213 }
214}
215
216} // namespace planning
217} // 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
Frame holds all data for one planning cycle.
Definition frame.h:62
const common::TrajectoryPoint & PlanningStartPoint() const
Definition frame.cc:79
void SetBlockingObstacle(bool blocking)
Definition obstacle.h:216
const DiscretizedPath & discretized_path() const
Definition path_data.cc:90
PathDecision represents all obstacle decisions on one path.
const Obstacle * Find(const std::string &object_id) const
const IndexedList< std::string, Obstacle > & obstacles() const
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
planning_internal::Debug * mutable_debug()
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
std::shared_ptr< DependencyInjector > injector_
Definition task.h:59
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
class register implement
Definition arena_queue.h:37
: data with map info and obstacle info