Apollo 11.0
自动驾驶开放平台
right_of_way.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 <limits>
20#include <memory>
21#include <string>
22#include <unordered_set>
23#include <vector>
24
30
31namespace apollo {
32namespace prediction {
33
37
38void RightOfWay::Analyze(ContainerManager* container_manager) {
39 ObstaclesContainer* obstacles_container =
40 container_manager->GetContainer<ObstaclesContainer>(
42 if (obstacles_container == nullptr) {
43 AERROR << "Null obstacles container found";
44 return;
45 }
46
47 ADCTrajectoryContainer* adc_trajectory_container =
48 container_manager->GetContainer<ADCTrajectoryContainer>(
50 if (adc_trajectory_container == nullptr) {
51 AERROR << "adc_trajectory_container is nullptr";
52 return;
53 }
54 const std::vector<std::string>& lane_ids =
55 adc_trajectory_container->GetADCLaneIDSequence();
56 if (lane_ids.empty()) {
57 return;
58 }
59
60 auto pose_container = container_manager->GetContainer<PoseContainer>(
62 if (pose_container == nullptr) {
63 AERROR << "Pose container pointer is a null pointer.";
64 return;
65 }
66 const PerceptionObstacle* pose_obstacle_ptr =
67 pose_container->ToPerceptionObstacle();
68 if (pose_obstacle_ptr == nullptr) {
69 AERROR << "Pose obstacle pointer is a null pointer.";
70 return;
71 }
72 double pose_x = pose_obstacle_ptr->position().x();
73 double pose_y = pose_obstacle_ptr->position().y();
74 double ego_vehicle_s = std::numeric_limits<double>::max();
75 double ego_vehicle_l = std::numeric_limits<double>::max();
76 double accumulated_s = 0.0;
77 std::string ego_lane_id = "";
78 // loop for lane_ids to findout ego_vehicle_s and lane_id
79 for (const std::string& lane_id : lane_ids) {
80 std::shared_ptr<const LaneInfo> lane_info_ptr =
82 if (lane_info_ptr == nullptr) {
83 AERROR << "Null lane info pointer found.";
84 continue;
85 }
86 double s = 0.0;
87 double l = 0.0;
88 if (PredictionMap::GetProjection({pose_x, pose_y}, lane_info_ptr, &s, &l)) {
89 if (std::fabs(l) < std::fabs(ego_vehicle_l)) {
90 ego_vehicle_s = accumulated_s + s;
91 ego_vehicle_l = l;
92 ego_lane_id = lane_id;
93 }
94 }
95 accumulated_s += lane_info_ptr->total_length();
96 }
97
98 // loop again to assign ego_back_lane_id_set_ & ego_front_lane_id_set_
99 accumulated_s = 0.0;
100 std::unordered_set<std::string> ego_back_lane_id_set_;
101 std::unordered_set<std::string> ego_front_lane_id_set_;
102 for (const std::string& lane_id : lane_ids) {
103 std::shared_ptr<const LaneInfo> lane_info_ptr =
105 if (lane_info_ptr == nullptr) {
106 AERROR << "Null lane info pointer found.";
107 continue;
108 }
109 accumulated_s += lane_info_ptr->total_length();
110 if (accumulated_s < ego_vehicle_s) {
111 ego_back_lane_id_set_.insert(lane_id);
112 } else if (accumulated_s > ego_vehicle_s) {
113 ego_front_lane_id_set_.insert(lane_id);
114 }
115 }
116
117 // then loop through all obstacle vehicles
118 for (const int id :
119 obstacles_container->curr_frame_considered_obstacle_ids()) {
120 Obstacle* obstacle_ptr = obstacles_container->GetObstacle(id);
121 if (obstacle_ptr == nullptr) {
122 continue;
123 }
124 Feature* latest_feature_ptr = obstacle_ptr->mutable_latest_feature();
125 if (latest_feature_ptr->type() != PerceptionObstacle::VEHICLE) {
126 continue;
127 }
128 ADEBUG << "RightOfWay for obstacle [" << latest_feature_ptr->id() << "], "
129 << "with lane_sequence_size: "
130 << latest_feature_ptr->lane().lane_graph().lane_sequence_size();
131 for (auto& lane_sequence : *latest_feature_ptr->mutable_lane()
132 ->mutable_lane_graph()
133 ->mutable_lane_sequence()) {
134 accumulated_s = 0.0;
135 for (auto lane_segment : lane_sequence.lane_segment()) {
136 accumulated_s += lane_segment.end_s() - lane_segment.start_s();
137 // set lower righ_of_way for turn lanes
138 if (lane_segment.lane_turn_type() == 2) { // left_turn
139 lane_sequence.set_right_of_way(-20);
140 } else if (lane_segment.lane_turn_type() == 3) { // right_turn
141 lane_sequence.set_right_of_way(-10);
142 }
143 if (accumulated_s > 50.0) {
144 break;
145 }
146 }
147 }
148 }
149}
150
151} // namespace prediction
152} // namespace apollo
ADC trajectory container
const std::vector< std::string > & GetADCLaneIDSequence() const
T * GetContainer(const common::adapter::AdapterConfig::MessageType &type)
Get mutable container
Prediction obstacle.
Definition obstacle.h:52
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
Definition obstacle.cc:88
const std::vector< int > & curr_frame_considered_obstacle_ids()
Get non-ignore obstacle IDs in the current frame
Obstacle * GetObstacle(const int id)
Get obstacle pointer
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
static bool GetProjection(const Eigen::Vector2d &position, const std::shared_ptr< const hdmap::LaneInfo > lane_info, double *s, double *l)
Get the frenet coordinates (s, l) on a lane by a position.
static void Analyze(ContainerManager *container_manager)
Set right_of_way for all lane_sequence
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
Obstacles container
Obstacles container
optional apollo::common::Point3D position
optional apollo::perception::PerceptionObstacle::Type type