Apollo 11.0
自动驾驶开放平台
adc_trajectory_container.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 <utility>
20
22
23namespace apollo {
24namespace prediction {
25
31
33 : adc_junction_info_ptr_(nullptr), s_dist_to_junction_(0.0) {}
34
36 const ::google::protobuf::Message& message) {
37 adc_lane_ids_.clear();
38 adc_lane_seq_.clear();
39 adc_target_lane_ids_.clear();
40 adc_target_lane_seq_.clear();
41 adc_junction_polygon_ = std::move(Polygon2d());
42
43 adc_trajectory_.CopyFrom(dynamic_cast<const ADCTrajectory&>(message));
44 ADEBUG << "Received a planning message ["
45 << adc_trajectory_.ShortDebugString() << "].";
46
47 // Find ADC lane sequence
48 SetLaneSequence();
49 ADEBUG << "Generate an ADC lane id sequence [" << ToString(adc_lane_seq_)
50 << "].";
51
52 // Find ADC target lane sequence
53 SetTargetLaneSequence();
54 ADEBUG << "Generate an ADC target lane id sequence ["
55 << ToString(adc_target_lane_seq_) << "].";
56}
57
59 if (adc_junction_polygon_.points().size() < 3) {
60 return false;
61 }
62 bool in_polygon = adc_junction_polygon_.IsPointIn({point.x(), point.y()});
63
64 bool on_virtual_lane = false;
65 if (point.has_lane_id()) {
66 on_virtual_lane = PredictionMap::IsVirtualLane(point.lane_id());
67 }
68 if (!on_virtual_lane) {
69 on_virtual_lane = PredictionMap::OnVirtualLane({point.x(), point.y()},
70 FLAGS_virtual_lane_radius);
71 }
72 return in_polygon && on_virtual_lane;
73}
74
76 return adc_trajectory_.has_right_of_way_status() &&
78}
79
80void ADCTrajectoryContainer::SetJunction(const std::string& junction_id,
81 const double distance) {
82 std::shared_ptr<const JunctionInfo> junction_info =
83 PredictionMap::JunctionById(junction_id);
84 if (junction_info != nullptr && junction_info->junction().has_polygon()) {
85 std::vector<Vec2d> vertices;
86 for (const auto& point : junction_info->junction().polygon().point()) {
87 vertices.emplace_back(point.x(), point.y());
88 }
89 if (vertices.size() >= 3) {
90 adc_junction_info_ptr_ = junction_info;
91 s_dist_to_junction_ = distance;
92 adc_junction_polygon_ = std::move(Polygon2d{vertices});
93 }
94 }
95}
96
97void ADCTrajectoryContainer::SetJunctionPolygon() {
98 std::shared_ptr<const JunctionInfo> junction_info(nullptr);
99
100 double s_start = 0.0;
101 double s_at_junction = 0.0;
102 if (adc_trajectory_.trajectory_point_size() > 0) {
103 s_start = adc_trajectory_.trajectory_point(0).path_point().s();
104 }
105 for (int i = 0; i < adc_trajectory_.trajectory_point_size(); ++i) {
106 double s = adc_trajectory_.trajectory_point(i).path_point().s();
107
108 if (s > FLAGS_adc_trajectory_search_length) {
109 break;
110 }
111
112 if (junction_info != nullptr) {
113 s_at_junction = s;
114 break;
115 }
116
117 double x = adc_trajectory_.trajectory_point(i).path_point().x();
118 double y = adc_trajectory_.trajectory_point(i).path_point().y();
119 std::vector<std::shared_ptr<const JunctionInfo>> junctions =
120 PredictionMap::GetJunctions({x, y}, FLAGS_junction_search_radius);
121 if (!junctions.empty() && junctions.front() != nullptr) {
122 junction_info = junctions.front();
123 }
124 }
125
126 if (junction_info != nullptr && junction_info->junction().has_polygon()) {
127 std::vector<Vec2d> vertices;
128 for (const auto& point : junction_info->junction().polygon().point()) {
129 vertices.emplace_back(point.x(), point.y());
130 }
131 if (vertices.size() >= 3) {
132 adc_junction_info_ptr_ = junction_info;
133 s_dist_to_junction_ = s_at_junction - s_start;
134 adc_junction_polygon_ = std::move(Polygon2d{vertices});
135 }
136 }
137}
138
139std::shared_ptr<const apollo::hdmap::JunctionInfo>
141 return adc_junction_info_ptr_;
142}
143
145 return s_dist_to_junction_;
146}
147
149 return adc_trajectory_;
150}
151
153 const std::string& lane_id) const {
154 return adc_lane_ids_.find(lane_id) != adc_lane_ids_.end();
155}
156
158 const std::string& lane_id) const {
159 return adc_target_lane_ids_.find(lane_id) != adc_target_lane_ids_.end();
160}
161
162void ADCTrajectoryContainer::SetLaneSequence() {
163 for (const auto& lane : adc_trajectory_.lane_id()) {
164 if (!lane.id().empty()) {
165 if (adc_lane_seq_.empty() || lane.id() != adc_lane_seq_.back()) {
166 adc_lane_seq_.emplace_back(lane.id());
167 }
168 }
169 }
170 adc_lane_ids_.clear();
171 adc_lane_ids_.insert(adc_lane_seq_.begin(), adc_lane_seq_.end());
172}
173
174void ADCTrajectoryContainer::SetTargetLaneSequence() {
175 for (const auto& lane : adc_trajectory_.target_lane_id()) {
176 if (!lane.id().empty()) {
177 if (adc_target_lane_seq_.empty() ||
178 lane.id() != adc_target_lane_seq_.back()) {
179 adc_target_lane_seq_.emplace_back(lane.id());
180 }
181 }
182 }
183 adc_target_lane_ids_.clear();
184 adc_target_lane_ids_.insert(adc_target_lane_seq_.begin(),
185 adc_target_lane_seq_.end());
186}
187
188std::string ADCTrajectoryContainer::ToString(
189 const std::unordered_set<std::string>& lane_ids) {
190 std::string str_lane_sequence = "";
191 auto it = lane_ids.begin();
192 if (it != lane_ids.end()) {
193 str_lane_sequence += (*it);
194 ++it;
195 }
196 for (; it != lane_ids.end(); ++it) {
197 str_lane_sequence += ("->" + *it);
198 }
199 return str_lane_sequence;
200}
201
202std::string ADCTrajectoryContainer::ToString(
203 const std::vector<std::string>& lane_ids) {
204 std::string str_lane_sequence = "";
205 auto it = lane_ids.begin();
206 if (it != lane_ids.end()) {
207 str_lane_sequence += (*it);
208 ++it;
209 }
210 for (; it != lane_ids.end(); ++it) {
211 str_lane_sequence += ("->" + *it);
212 }
213 return str_lane_sequence;
214}
215
217 const LaneSequence& lane_sequence) const {
218 for (const auto& lane_segment : lane_sequence.lane_segment()) {
219 std::string lane_id = lane_segment.lane_id();
220 if (adc_lane_ids_.find(lane_id) != adc_lane_ids_.end()) {
221 return true;
222 }
223 }
224 return false;
225}
226
228 for (auto it = adc_lane_seq_.begin(); it != adc_lane_seq_.end(); ++it) {
229 auto lane_info = PredictionMap::LaneById(*it);
230 if (lane_info != nullptr && lane_info->IsOnLane(position)) {
231 adc_lane_ids_.clear();
232 adc_lane_ids_.insert(it, adc_lane_seq_.end());
233 break;
234 }
235 }
236 ADEBUG << "Generate an ADC lane ids [" << ToString(adc_lane_ids_) << "].";
237}
238
239const std::vector<std::string>& ADCTrajectoryContainer::GetADCLaneIDSequence()
240 const {
241 return adc_lane_seq_;
242}
243
244const std::vector<std::string>&
246 return adc_target_lane_seq_;
247}
248
249} // namespace prediction
250} // namespace apollo
ADC trajectory container
The class of polygon in 2-D.
Definition polygon2d.h:42
bool IsPointIn(const Vec2d &point) const
Check if a point is within the polygon.
Definition polygon2d.cc:130
const std::vector< Vec2d > & points() const
Get the vertices of the polygon.
Definition polygon2d.h:65
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
bool IsLaneIdInReferenceLine(const std::string &lane_id) const
Determine if a lane ID is in the reference line
const std::vector< std::string > & GetADCTargetLaneIDSequence() const
void SetJunction(const std::string &junction_id, const double distance)
bool IsPointInJunction(const common::PathPoint &point) const
Check if a point is in the first junction of the adc trajectory
const planning::ADCTrajectory & adc_trajectory() const
Get ADC planning trajectory
bool IsLaneIdInTargetReferenceLine(const std::string &lane_id) const
void Insert(const ::google::protobuf::Message &message) override
Insert a data message into the container
bool IsProtected() const
Get the right-of-way status of ADC
bool HasOverlap(const LaneSequence &lane_sequence) const
Has overlap with ADC trajectory
double ADCDistanceToJunction() const
Compute ADC's distance to junction
void SetPosition(const common::math::Vec2d &position)
Set ADC position
std::shared_ptr< const hdmap::JunctionInfo > ADCJunction() const
Get ADC junction
const std::vector< std::string > & GetADCLaneIDSequence() const
static std::shared_ptr< const hdmap::JunctionInfo > JunctionById(const std::string &id)
Get a shared pointer to a junction by junction ID.
static bool OnVirtualLane(const Eigen::Vector2d &position, const double radius)
Determine if a point is on a virtual lane.
static bool IsVirtualLane(const std::string &lane_id)
Determine if a lane is a virtual lane.
static std::vector< std::shared_ptr< const apollo::hdmap::JunctionInfo > > GetJunctions(const Eigen::Vector2d &point, const double radius)
Get a list of junctions given a point and a search radius
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
#define ADEBUG
Definition log.h:41
class register implement
Definition arena_queue.h:37
repeated apollo::common::TrajectoryPoint trajectory_point
optional RightOfWayStatus right_of_way_status
repeated LaneSegment lane_segment