Apollo 11.0
自动驾驶开放平台
autotuning_raw_feature_generator.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
18
19#include <string>
20
22
23namespace apollo {
24namespace planning {
25
26namespace {
27constexpr double kMinTimeRange = 0.001;
28// used when speed profile is invalid
29constexpr double kDefaultSpeedLimit = 10.0;
30
31constexpr double kMaxAwareDistance = 1e3;
32} // namespace
33
36
38 const double time_range, const size_t num_points,
39 const ReferenceLineInfo& reference_line_info, const Frame& frame,
40 const SpeedLimit& speed_limit)
41 : reference_line_info_(reference_line_info),
42 frame_(frame),
43 speed_limit_(speed_limit),
44 obs_boundaries_(num_points, std::vector<std::array<double, 3>>()),
45 stop_boundaries_(num_points, std::vector<std::array<double, 3>>()),
46 nudge_boundaries_(num_points, std::vector<std::array<double, 3>>()),
47 side_pass_boundaries_(num_points, std::vector<std::array<double, 3>>()) {
48 CHECK_GT(num_points, 0U);
49 CHECK_GT(time_range, kMinTimeRange);
50 double res = time_range / static_cast<double>(num_points);
51 for (double t = 0; t < res + time_range; t += res) {
52 eval_time_.push_back(t);
53 }
54}
55
57 const std::vector<common::TrajectoryPoint>& trajectory,
58 autotuning::TrajectoryRawFeature* const trajectory_feature) const {
59 return common::Status::OK();
60}
61
68
69common::Status AutotuningRawFeatureGenerator::EvaluateSpeedPoint(
70 const common::SpeedPoint& speed_point, const size_t index,
71 autotuning::TrajectoryPointRawFeature* const trajectory_point_feature)
72 const {
73 auto* speed_feature = trajectory_point_feature->mutable_speed_feature();
74 // setup basic speed profile
75 const double s = speed_point.s();
76 speed_feature->set_s(s);
77 speed_feature->set_t(speed_point.t());
78 speed_feature->set_v(speed_point.v());
79 speed_feature->set_a(speed_point.a());
80 speed_feature->set_j(speed_point.da());
81
82 // get speed limit at certain s();
83 if (speed_limit_.speed_limit_points().front().first > s) {
84 speed_feature->set_speed_limit(kDefaultSpeedLimit);
85 } else {
86 double cur_speed_limit = speed_limit_.GetSpeedLimitByS(s);
87 speed_feature->set_speed_limit(cur_speed_limit);
88 }
89
90 // extracting obstacle related infos
91
92 autotuning::SpeedPointRawFeature_ObjectDecisionFeature* decision_obj =
93 nullptr;
94 for (const auto& stop_obs : stop_boundaries_[index]) {
95 double lower_s = stop_obs[0];
96 double speed = stop_obs[2];
97 double distance = 0.0;
98 // stop line is in the front
99 if (lower_s < s) {
100 distance = lower_s - s;
101 decision_obj = speed_feature->add_stop();
102 } else {
103 decision_obj = speed_feature->add_collision();
104 }
105 decision_obj->set_relative_s(distance);
106 decision_obj->set_relative_v(speed - speed_point.v());
107 }
108
109 for (const auto& obs : obs_boundaries_[index]) {
110 double lower_s = obs[0];
111 double upper_s = obs[1];
112 double speed = obs[2];
113 double distance = 0.0;
114 if (upper_s < s) {
115 decision_obj = speed_feature->add_overtake();
116 distance = s - upper_s;
117 } else if (lower_s > s) {
118 decision_obj = speed_feature->add_follow();
119 distance = lower_s - s;
120 } else {
121 decision_obj = speed_feature->add_collision();
122 }
123 decision_obj->set_relative_s(distance);
124 decision_obj->set_relative_v(speed - speed_point.v());
125 }
126 return common::Status::OK();
127}
128
130 const std::vector<common::SpeedPoint>& speed_profile,
131 autotuning::TrajectoryRawFeature* const trajectory_feature) const {
132 if (speed_profile.size() != eval_time_.size()) {
133 const std::string msg = "mismatched evaluated time and speed profile size";
134 AERROR << msg;
135 return Status(ErrorCode::PLANNING_ERROR, msg);
136 }
137 for (size_t i = 0; i < eval_time_.size(); ++i) {
138 auto* trajectory_point_feature = trajectory_feature->add_point_feature();
139 auto status =
140 EvaluateSpeedPoint(speed_profile[i], i, trajectory_point_feature);
141 if (status != common::Status::OK()) {
142 const std::string msg = "Extracting speed profile error";
143 AERROR << msg;
144 return Status(ErrorCode::PLANNING_ERROR, msg);
145 }
146 }
147 return common::Status::OK();
148}
149
150void AutotuningRawFeatureGenerator::GenerateSTBoundaries(
151 const ReferenceLineInfo& reference_line_info) {
152 const auto& path_decision = reference_line_info.path_decision();
153 for (auto* obstacle : path_decision.obstacles().Items()) {
154 auto id = obstacle->Id();
155 const double speed = obstacle->speed();
156 if (!obstacle->path_st_boundary().IsEmpty()) {
157 // fill discretized boundary info
158 ConvertToDiscretizedBoundaries(obstacle->path_st_boundary(), speed);
159 }
160 }
161}
162
163void AutotuningRawFeatureGenerator::ConvertToDiscretizedBoundaries(
164 const STBoundary& boundary, const double speed) {
165 for (size_t i = 0; i < eval_time_.size(); ++i) {
166 double upper = 0.0;
167 double lower = 0.0;
168 bool suc = boundary.GetBoundarySRange(eval_time_[i], &upper, &lower);
169 if (suc) {
170 if (boundary.boundary_type() == STBoundary::BoundaryType::STOP) {
171 stop_boundaries_[i].push_back({{lower, upper, speed}});
172 } else {
173 obs_boundaries_[i].push_back({{lower, upper, speed}});
174 }
175 }
176 }
177}
178
179} // namespace planning
180} // 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
common::Status EvaluateTrajectory(const std::vector< common::TrajectoryPoint > &trajectory, autotuning::TrajectoryRawFeature *const trajectory_feature) const
evaluate trajectory with environment, generate model trajectory features
common::Status EvaluateSpeedProfile(const std::vector< common::SpeedPoint > &speed_profile, autotuning::TrajectoryRawFeature *const trajectory_feature) const
EvaluateSpeed Profile shall match the time range as well as resolution
common::Status EvaluateTrajectoryPoint(const common::TrajectoryPoint &trajectory_point, autotuning::TrajectoryPointRawFeature *const trajectory_point_feature) const
evaluate trajectory point with environment, generate model trajectory features
AutotuningRawFeatureGenerator(const double time_range, const size_t num_points, const ReferenceLineInfo &reference_line_info, const Frame &frame, const SpeedLimit &speed_limit)
Frame holds all data for one planning cycle.
Definition frame.h:62
ReferenceLineInfo holds all data for one reference line.
const std::vector< std::pair< double, double > > & speed_limit_points() const
double GetSpeedLimitByS(const double s) const
Planning module main class.
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
Definition future.h:29