Apollo 10.0
自动驾驶开放平台
feature_extractor.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
20
21namespace apollo {
22namespace prediction {
23
24using common::adapter::AdapterConfig;
25using common::math::Vec2d;
26using hdmap::JunctionInfo;
27using hdmap::LaneInfo;
28using LaneInfoPtr = std::shared_ptr<const LaneInfo>;
29using JunctionInfoPtr = std::shared_ptr<const JunctionInfo>;
30
32 ContainerManager* container_manager) {
33 EnvironmentFeatures environment_features;
34
35 auto ego_state_container = container_manager->GetContainer<PoseContainer>(
37
38 if (ego_state_container == nullptr ||
39 ego_state_container->ToPerceptionObstacle() == nullptr) {
40 AERROR << "Null ego state container found or "
41 "the container pointer is nullptr";
42 return environment_features;
43 }
44
45 auto ptr_ego_state = ego_state_container->ToPerceptionObstacle();
46 if (!ptr_ego_state->has_position() || !ptr_ego_state->position().has_x() ||
47 !ptr_ego_state->position().has_y() || !ptr_ego_state->has_theta() ||
48 !ptr_ego_state->has_velocity() || !ptr_ego_state->velocity().has_x() ||
49 !ptr_ego_state->velocity().has_y()) {
50 AERROR << "Incomplete ego pose information.";
51 return environment_features;
52 }
53
54 if (std::isnan(ptr_ego_state->position().x()) ||
55 std::isnan(ptr_ego_state->position().y()) ||
56 std::isnan(ptr_ego_state->theta()) ||
57 std::isnan(ptr_ego_state->velocity().x()) ||
58 std::isnan(ptr_ego_state->velocity().y())) {
59 AERROR << "nan found in ego state";
60 return environment_features;
61 }
62
63 Vec2d ego_position(ptr_ego_state->position().x(),
64 ptr_ego_state->position().y());
65
66 Vec2d ego_velocity(ptr_ego_state->velocity().x(),
67 ptr_ego_state->velocity().y());
68
69 environment_features.set_ego_speed(ego_velocity.Length());
70 environment_features.set_ego_heading(ptr_ego_state->theta());
71
72 auto ptr_ego_lane =
73 GetEgoLane(ptr_ego_state->position(), ptr_ego_state->theta());
74
75 ExtractEgoLaneFeatures(&environment_features, ptr_ego_lane, ego_position);
76
77 ExtractNeighborLaneFeatures(&environment_features, ptr_ego_lane,
78 ego_position);
79
80 ExtractFrontJunctionFeatures(&environment_features, container_manager);
81
82 return environment_features;
83}
84
85void FeatureExtractor::ExtractEgoLaneFeatures(
86 EnvironmentFeatures* ptr_environment_features,
87 const LaneInfoPtr& ptr_ego_lane, const common::math::Vec2d& ego_position) {
88 if (ptr_ego_lane == nullptr) {
89 ADEBUG << "Ego vehicle is not on any lane.";
90 return;
91 }
92 ADEBUG << "Ego vehicle is on lane [" << ptr_ego_lane->id().id() << "]";
93 double curr_lane_s = 0.0;
94 double curr_lane_l = 0.0;
95 ptr_ego_lane->GetProjection(ego_position, &curr_lane_s, &curr_lane_l);
96 ptr_environment_features->SetEgoLane(ptr_ego_lane->id().id(), curr_lane_s);
97
98 double threshold = 1.0;
99 auto ptr_left_neighbor_lane = PredictionMap::GetLeftNeighborLane(
100 ptr_ego_lane, {ego_position.x(), ego_position.y()}, threshold);
101
102 if (ptr_left_neighbor_lane == nullptr &&
103 ptr_ego_lane->lane().has_left_boundary() &&
104 ptr_ego_lane->lane().left_boundary().boundary_type_size() != 0 &&
105 ptr_ego_lane->lane().left_boundary().boundary_type(0).types_size() != 0 &&
106 ptr_ego_lane->lane().left_boundary().boundary_type(0).types(0) !=
108 const auto& reverse_lanes =
109 ptr_ego_lane->lane().left_neighbor_reverse_lane_id();
110 std::for_each(
111 reverse_lanes.begin(), reverse_lanes.end(),
112 [&ptr_environment_features](decltype(*reverse_lanes.begin())& t) {
113 ptr_environment_features->AddNonneglectableReverseLanes(t.id());
114 });
115 }
116}
117
118void FeatureExtractor::ExtractNeighborLaneFeatures(
119 EnvironmentFeatures* ptr_environment_features,
120 const LaneInfoPtr& ptr_ego_lane, const Vec2d& ego_position) {
121 if (ptr_ego_lane == nullptr) {
122 ADEBUG << "Ego vehicle is not on any lane.";
123 return;
124 }
125
126 auto ptr_left_neighbor_lane = PredictionMap::GetLeftNeighborLane(
127 ptr_ego_lane, {ego_position.x(), ego_position.y()},
128 FLAGS_lane_distance_threshold);
129
130 if (ptr_left_neighbor_lane != nullptr) {
131 double left_neighbor_lane_s = 0.0;
132 double left_neighbor_lane_l = 0.0;
133 ptr_left_neighbor_lane->GetProjection(ego_position, &left_neighbor_lane_s,
134 &left_neighbor_lane_l);
135 ptr_environment_features->SetLeftNeighborLane(
136 ptr_left_neighbor_lane->id().id(), left_neighbor_lane_s);
137 }
138
139 auto ptr_right_neighbor_lane = PredictionMap::GetRightNeighborLane(
140 ptr_ego_lane, {ego_position.x(), ego_position.y()},
141 FLAGS_lane_distance_threshold);
142
143 if (ptr_right_neighbor_lane != nullptr) {
144 double right_neighbor_lane_s = 0.0;
145 double right_neighbor_lane_l = 0.0;
146 ptr_right_neighbor_lane->GetProjection(ego_position, &right_neighbor_lane_s,
147 &right_neighbor_lane_l);
148 ptr_environment_features->SetRightNeighborLane(
149 ptr_right_neighbor_lane->id().id(), right_neighbor_lane_s);
150 }
151}
152
153void FeatureExtractor::ExtractFrontJunctionFeatures(
154 EnvironmentFeatures* ptr_environment_features,
155 ContainerManager* container_manager) {
156 auto ego_trajectory_container =
157 container_manager->GetContainer<ADCTrajectoryContainer>(
159 if (ego_trajectory_container == nullptr) {
160 AERROR << "Null ego trajectory container";
161 return;
162 }
163 JunctionInfoPtr junction = ego_trajectory_container->ADCJunction();
164 if (junction == nullptr) {
165 return;
166 }
167 // Only consider junction have overlap with signal or stop_sign
168 bool need_consider = FLAGS_enable_all_junction;
169 for (const auto& overlap_id : junction->junction().overlap_id()) {
170 if (PredictionMap::OverlapById(overlap_id.id()) != nullptr) {
171 for (const auto& object :
172 PredictionMap::OverlapById(overlap_id.id())->overlap().object()) {
173 if (object.has_signal_overlap_info() ||
174 object.has_stop_sign_overlap_info()) {
175 need_consider = true;
176 }
177 }
178 }
179 }
180 if (need_consider) {
181 ptr_environment_features->SetFrontJunction(
182 junction->id().id(), ego_trajectory_container->ADCDistanceToJunction());
183 }
184}
185
186LaneInfoPtr FeatureExtractor::GetEgoLane(const common::Point3D& position,
187 const double heading) {
188 common::PointENU position_enu;
189 position_enu.set_x(position.x());
190 position_enu.set_y(position.y());
191 position_enu.set_z(position.z());
192
194 position_enu, FLAGS_lane_distance_threshold, heading,
195 FLAGS_lane_angle_difference_threshold);
196}
197
198} // namespace prediction
199} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double Length() const
Gets the length of the vector
Definition vec2d.cc:33
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
T * GetContainer(const common::adapter::AdapterConfig::MessageType &type)
Get mutable container
void set_ego_heading(const double ego_heading)
void SetEgoLane(const std::string &lane_id, const double lane_s)
static EnvironmentFeatures ExtractEnvironmentFeatures(ContainerManager *container_manager)
Extract features for scenario analysis
static std::shared_ptr< const hdmap::LaneInfo > GetRightNeighborLane(const std::shared_ptr< const hdmap::LaneInfo > &ptr_ego_lane, const Eigen::Vector2d &ego_position, const double threshold)
static std::shared_ptr< const hdmap::LaneInfo > GetLeftNeighborLane(const std::shared_ptr< const hdmap::LaneInfo > &ptr_ego_lane, const Eigen::Vector2d &ego_position, const double threshold)
static std::shared_ptr< const apollo::hdmap::LaneInfo > GetMostLikelyCurrentLane(const common::PointENU &position, const double radius, const double heading, const double angle_diff_threshold)
Get the lane that the position is on with minimal angle diff
static std::shared_ptr< const hdmap::OverlapInfo > OverlapById(const std::string &id)
Get a shared pointer to an overlap by overlap ID.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
std::shared_ptr< const JunctionInfo > JunctionInfoPtr
std::shared_ptr< const LaneInfo > LaneInfoPtr
class register implement
Definition arena_queue.h:37