24using common::adapter::AdapterConfig;
25using common::math::Vec2d;
26using hdmap::JunctionInfo;
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;
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;
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;
63 Vec2d ego_position(ptr_ego_state->position().x(),
64 ptr_ego_state->position().y());
66 Vec2d ego_velocity(ptr_ego_state->velocity().x(),
67 ptr_ego_state->velocity().y());
73 GetEgoLane(ptr_ego_state->position(), ptr_ego_state->theta());
75 ExtractEgoLaneFeatures(&environment_features, ptr_ego_lane, ego_position);
77 ExtractNeighborLaneFeatures(&environment_features, ptr_ego_lane,
80 ExtractFrontJunctionFeatures(&environment_features, container_manager);
82 return environment_features;
85void FeatureExtractor::ExtractEgoLaneFeatures(
88 if (ptr_ego_lane ==
nullptr) {
89 ADEBUG <<
"Ego vehicle is not on any lane.";
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);
98 double threshold = 1.0;
100 ptr_ego_lane, {ego_position.
x(), ego_position.
y()}, threshold);
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();
111 reverse_lanes.begin(), reverse_lanes.end(),
112 [&ptr_environment_features](
decltype(*reverse_lanes.begin())& t) {
113 ptr_environment_features->AddNonneglectableReverseLanes(t.id());
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.";
127 ptr_ego_lane, {ego_position.x(), ego_position.y()},
128 FLAGS_lane_distance_threshold);
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);
140 ptr_ego_lane, {ego_position.x(), ego_position.y()},
141 FLAGS_lane_distance_threshold);
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);
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";
164 if (junction ==
nullptr) {
168 bool need_consider = FLAGS_enable_all_junction;
169 for (
const auto& overlap_id : junction->junction().overlap_id()) {
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;
181 ptr_environment_features->SetFrontJunction(
182 junction->id().id(), ego_trajectory_container->ADCDistanceToJunction());
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());
194 position_enu, FLAGS_lane_distance_threshold, heading,
195 FLAGS_lane_angle_difference_threshold);
Implements a class of 2-dimensional vectors.
double Length() const
Gets the length of the vector
double y() const
Getter for y component
double x() const
Getter for x component
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)
void set_ego_speed(const double ego_speed)
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.
std::shared_ptr< const JunctionInfo > JunctionInfoPtr
std::shared_ptr< const LaneInfo > LaneInfoPtr