Apollo 11.0
自动驾驶开放平台
autotuning_speed_feature_builder.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 <cmath>
20#include <string>
21
22#include "absl/strings/str_cat.h"
23
24#include "modules/common_msgs/basic_msgs/error_code.pb.h"
25
26#include "cyber/common/log.h"
27
30
31namespace apollo {
32namespace planning {
33
35 const autotuning::TrajectoryRawFeature& raw_feature,
36 autotuning::TrajectoryFeature* const input_feature) const {
37 if (input_feature == nullptr) {
38 const std::string msg = "input trajectory feature is empty";
39 AERROR << msg;
40 return Status(ErrorCode::PLANNING_ERROR, msg);
41 }
42
43 // number of input trajectory point
44 int n = input_feature->point_feature_size();
45 if (n != raw_feature.point_feature_size()) {
46 const std::string msg =
47 absl::StrCat("raw and input feature size mismatch. raw: ",
48 raw_feature.point_feature_size(), "; input: ", n);
49 AERROR << msg;
50 return Status(ErrorCode::PLANNING_ERROR, msg);
51 }
52
53 for (int i = 0; i < n; ++i) {
54 const auto& raw_point_feature = raw_feature.point_feature(i);
55 auto* point_feature = input_feature->mutable_point_feature(i);
56 auto status = BuildPointFeature(raw_point_feature, point_feature);
57 if (status != Status::OK()) {
58 const std::string msg = "pointwise feature adding incorrect";
59 return Status(ErrorCode::PLANNING_ERROR, msg);
60 }
61 }
62 return Status::OK();
63}
64
66 const autotuning::TrajectoryPointRawFeature& raw_point_feature,
67 autotuning::TrajectoryPointwiseFeature* const point_feature) const {
68 // set up basic feature:
69 double v = raw_point_feature.speed_feature().v();
70 auto* speed_feature = point_feature->mutable_speed_input_feature();
71 speed_feature->set_s(raw_point_feature.speed_feature().s());
72 speed_feature->set_t(raw_point_feature.speed_feature().t());
73 speed_feature->set_v(v);
74 speed_feature->set_acc(raw_point_feature.speed_feature().a());
75 speed_feature->set_jerk(raw_point_feature.speed_feature().j());
76 speed_feature->set_speed_limit(
77 raw_point_feature.speed_feature().speed_limit());
78
79 double kappa = raw_point_feature.path_feature().cartesian_coord().kappa();
80 double lateral_acc = v * v * kappa;
81
82 speed_feature->set_path_curvature_abs(std::fabs(kappa));
83 speed_feature->set_lateral_acc(lateral_acc);
84
85 // boundary feature, virtual obstacle , e.g. routing end
86 for (int i = 0; i < raw_point_feature.speed_feature().virtual_decision_size();
87 ++i) {
88 const auto& obj_decision =
89 raw_point_feature.speed_feature().virtual_decision(i);
90 auto* input_decision = speed_feature->add_virtual_obs_feature();
91 map_obstacle_feature(obj_decision, input_decision);
92 }
93
94 // boundary feature, stop obstacle, based on stop decision
95 for (int i = 0; i < raw_point_feature.speed_feature().stop_size(); ++i) {
96 const auto& obj_decision = raw_point_feature.speed_feature().stop(i);
97 auto* input_decision = speed_feature->add_stop_obs_feature();
98 map_obstacle_feature(obj_decision, input_decision);
99 }
100
101 // boundary feature, overtake obstacle, based on overtake obstacle decision
102 for (int i = 0; i < raw_point_feature.speed_feature().overtake_size(); ++i) {
103 const auto& obj_decision = raw_point_feature.speed_feature().overtake(i);
104 auto* input_decision = speed_feature->add_overtake_obs_feature();
105 map_obstacle_feature(obj_decision, input_decision);
106 }
107
108 // boundary feature, yield/follow obstacle, based on yield/follow obstacle
109 // decision
110 for (int i = 0; i < raw_point_feature.speed_feature().follow_size(); ++i) {
111 const auto& obj_decision = raw_point_feature.speed_feature().follow(i);
112 auto* input_decision = speed_feature->add_follow_obs_feature();
113 map_obstacle_feature(obj_decision, input_decision);
114 }
115
116 // boundary feature, nudge obstacle feature
117 for (int i = 0; i < raw_point_feature.speed_feature().nudge_size(); ++i) {
118 const auto& obj_decision = raw_point_feature.speed_feature().nudge(i);
119 auto* input_decision = speed_feature->add_nudge_obs_feature();
120 map_nudge_obs_feature(obj_decision, input_decision);
121 }
122
123 // boundary feature, side pass feature
124 for (int i = 0; i < raw_point_feature.speed_feature().sidepass_front_size();
125 ++i) {
126 const auto& obj_decision =
127 raw_point_feature.speed_feature().sidepass_front(i);
128 auto* input_decision = speed_feature->add_sidepass_front_obs_feature();
129 map_sidepass_obs_feature(obj_decision, input_decision);
130 }
131 for (int i = 0; i < raw_point_feature.speed_feature().sidepass_rear_size();
132 ++i) {
133 const auto& obj_decision =
134 raw_point_feature.speed_feature().sidepass_rear(i);
135 auto* input_decision = speed_feature->add_sidepass_rear_obs_feature();
136 map_sidepass_obs_feature(obj_decision, input_decision);
137 }
138 return Status::OK();
139}
140
141void AutotuningSpeedFeatureBuilder::map_obstacle_feature(
142 const autotuning::SpeedPointRawFeature_ObjectDecisionFeature&
143 obj_raw_feature,
144 autotuning::SpeedPointwiseFeature_ObstacleFeature* const input_feature)
145 const {
146 input_feature->set_longitudinal_distance(
147 std::fabs(obj_raw_feature.relative_s()));
148 input_feature->set_obstacle_speed(obj_raw_feature.speed());
149 input_feature->set_relative_v(obj_raw_feature.relative_v());
150 input_feature->set_lateral_distance(std::fabs(obj_raw_feature.relative_l()));
151}
152
156void AutotuningSpeedFeatureBuilder::map_nudge_obs_feature(
157 const autotuning::SpeedPointRawFeature_ObjectDecisionFeature&
158 obj_raw_feature,
159 autotuning::SpeedPointwiseFeature_ObstacleFeature* const input_feature)
160 const {
161 input_feature->set_longitudinal_distance(
162 std::fabs(obj_raw_feature.relative_s()));
163 input_feature->set_obstacle_speed(obj_raw_feature.speed());
164 input_feature->set_relative_v(obj_raw_feature.relative_v());
165 input_feature->set_lateral_distance(std::fabs(obj_raw_feature.relative_l()));
166}
167
171void AutotuningSpeedFeatureBuilder::map_sidepass_obs_feature(
172 const autotuning::SpeedPointRawFeature_ObjectDecisionFeature&
173 obj_raw_feature,
174 autotuning::SpeedPointwiseFeature_ObstacleFeature* const input_feature)
175 const {
176 input_feature->set_longitudinal_distance(
177 std::fabs(obj_raw_feature.relative_s()));
178 input_feature->set_obstacle_speed(obj_raw_feature.speed());
179 input_feature->set_relative_v(obj_raw_feature.relative_v());
180 input_feature->set_lateral_distance(std::fabs(obj_raw_feature.relative_l()));
181}
182} // namespace planning
183} // 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 BuildPointFeature(const autotuning::TrajectoryPointRawFeature &raw_point_feature, autotuning::TrajectoryPointwiseFeature *const point_feature) const override
common::Status BuildFeature(const autotuning::TrajectoryRawFeature &raw_feature, autotuning::TrajectoryFeature *const input_feature) const override
Planning module main class.
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37