Apollo 10.0
自动驾驶开放平台
reference_line.h
浏览该文件的文档.
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
21#pragma once
22
23#include <string>
24#include <utility>
25#include <vector>
26
27#include "modules/common_msgs/basic_msgs/pnc_point.pb.h"
28#include "modules/common_msgs/map_msgs/map.pb.h"
29#include "modules/common_msgs/map_msgs/map_geometry.pb.h"
30#include "modules/common_msgs/planning_msgs/sl_boundary.pb.h"
31#include "modules/common_msgs/routing_msgs/routing.pb.h"
32
36
37namespace apollo {
38namespace planning {
39
41 public:
42 ReferenceLine() = default;
43 explicit ReferenceLine(const ReferenceLine& reference_line) = default;
44 template <typename Iterator>
45 ReferenceLine(const Iterator begin, const Iterator end)
46 : reference_points_(begin, end),
47 map_path_(std::move(std::vector<hdmap::MapPathPoint>(begin, end))) {}
48 explicit ReferenceLine(const std::vector<ReferencePoint>& reference_points);
49 explicit ReferenceLine(const hdmap::Path& hdmap_path);
50
73 bool Stitch(const ReferenceLine& other);
74
75 bool Segment(const common::math::Vec2d& point, const double distance_backward,
76 const double distance_forward);
77
78 bool Segment(const double s, const double distance_backward,
79 const double distance_forward);
80
81 const hdmap::Path& map_path() const;
82 const std::vector<ReferencePoint>& reference_points() const;
83
84 ReferencePoint GetReferencePoint(const double s) const;
85
87 const common::PathPoint& path_point) const;
88
89 std::pair<std::array<double, 3>, std::array<double, 3>> ToFrenetFrame(
90 const common::TrajectoryPoint& traj_point) const;
91
92 std::vector<ReferencePoint> GetReferencePoints(double start_s,
93 double end_s) const;
94
95 size_t GetNearestReferenceIndex(const double s) const;
96
98
99 std::vector<hdmap::LaneSegment> GetLaneSegments(const double start_s,
100 const double end_s) const;
101
102 ReferencePoint GetNearestReferencePoint(const double s) const;
103
104 ReferencePoint GetReferencePoint(const double x, const double y) const;
105
107 const double start_s, const double end_s,
108 SLBoundary* const sl_boundary) const;
118 bool GetSLBoundary(const common::math::Box2d& box,
119 SLBoundary* const sl_boundary,
120 double warm_start_s = -1.0) const;
121 bool GetSLBoundary(const common::math::Polygon2d& polygon,
122 SLBoundary* const sl_boundary,
123 double warm_start_s = -1.0) const;
124 bool GetSLBoundary(const std::vector<common::math::Vec2d>& corners,
125 SLBoundary* const sl_boundary, double warm_start_s) const;
126 bool GetSLBoundary(const hdmap::Polygon& polygon,
127 SLBoundary* const sl_boundary) const;
128
129 bool SLToXY(const common::SLPoint& sl_point,
130 common::math::Vec2d* const xy_point) const;
141 bool XYToSL(const common::math::Vec2d& xy_point,
142 common::SLPoint* const sl_point,
143 double warm_start_s = -1.0) const;
144
145 bool XYToSL(const double heading, const common::math::Vec2d& xy_point,
146 common::SLPoint* const sl_point,
147 double warm_start_s = -1.0) const;
148 bool XYToSL(const common::math::Vec2d& xy_point,
149 common::SLPoint* const sl_point, double hueristic_start_s,
150 double hueristic_end_s) const;
151
152 template <class XYPoint>
153 bool XYToSL(const XYPoint& xy, common::SLPoint* const sl_point) const {
154 return XYToSL(common::math::Vec2d(xy.x(), xy.y()), sl_point);
155 }
156
157 bool GetLaneWidth(const double s, double* const lane_left_width,
158 double* const lane_right_width) const;
159
160 bool GetOffsetToMap(const double s, double* l_offset) const;
161
162 bool GetRoadWidth(const double s, double* const road_left_width,
163 double* const road_right_width) const;
164
165 hdmap::Road::Type GetRoadType(const double s) const;
167 const double s, hdmap::LaneBoundaryType::Type* const left_boundary_type,
168 hdmap::LaneBoundaryType::Type* const right_boundary_type) const;
169
170 void GetLaneFromS(const double s,
171 std::vector<hdmap::LaneInfoConstPtr>* lanes) const;
172
173 double GetDrivingWidth(const SLBoundary& sl_boundary) const;
174
178 bool IsOnLane(const common::SLPoint& sl_point) const;
179 bool IsOnLane(const common::math::Vec2d& vec2d_point) const;
180 template <class XYPoint>
181 bool IsOnLane(const XYPoint& xy) const {
182 return IsOnLane(common::math::Vec2d(xy.x(), xy.y()));
183 }
184 bool IsOnLane(const SLBoundary& sl_boundary) const;
185
190 bool IsOnRoad(const common::SLPoint& sl_point) const;
191 bool IsOnRoad(const common::math::Vec2d& vec2d_point) const;
192 bool IsOnRoad(const SLBoundary& sl_boundary) const;
193
202 bool IsBlockRoad(const common::math::Box2d& box2d, double gap) const;
203
207 bool HasOverlap(const common::math::Box2d& box) const;
208
209 double Length() const { return map_path_.length(); }
210
211 std::string DebugString() const;
212
213 double GetSpeedLimitFromS(const double s) const;
214
215 void AddSpeedLimit(double start_s, double end_s, double speed_limit);
216
217 uint32_t GetPriority() const { return priority_; }
218
219 void SetPriority(uint32_t priority) { priority_ = priority; }
220
221 const hdmap::Path& GetMapPath() const { return map_path_; }
222
223 void SetEgoPosition(common::math::Vec2d ego_pos) { ego_position_ = ego_pos; }
224
225 private:
244 static ReferencePoint Interpolate(const ReferencePoint& p0, const double s0,
245 const ReferencePoint& p1, const double s1,
246 const double s);
247 ReferencePoint InterpolateWithMatchedIndex(
248 const ReferencePoint& p0, const double s0, const ReferencePoint& p1,
249 const double s1, const hdmap::InterpolatedIndex& index) const;
250
251 static double FindMinDistancePoint(const ReferencePoint& p0, const double s0,
252 const ReferencePoint& p1, const double s1,
253 const double x, const double y);
254
255 private:
256 struct SpeedLimit {
257 double start_s = 0.0;
258 double end_s = 0.0;
259 double speed_limit = 0.0; // unit m/s
260 SpeedLimit() = default;
261 SpeedLimit(double _start_s, double _end_s, double _speed_limit)
262 : start_s(_start_s), end_s(_end_s), speed_limit(_speed_limit) {}
263 };
267 std::vector<SpeedLimit> speed_limit_;
268 std::vector<ReferencePoint> reference_points_;
269 hdmap::Path map_path_;
270 uint32_t priority_ = 0;
271 common::math::Vec2d ego_position_;
272};
273
274} // namespace planning
275} // namespace apollo
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double length() const
Definition path.h:294
const hdmap::Path & GetMapPath() const
bool GetApproximateSLBoundary(const common::math::Box2d &box, const double start_s, const double end_s, SLBoundary *const sl_boundary) const
bool IsOnRoad(const common::SLPoint &sl_point) const
: check if a box/point is on road (not on sideways/medians) along reference line
bool Segment(const common::math::Vec2d &point, const double distance_backward, const double distance_forward)
const hdmap::Path & map_path() const
bool IsOnLane(const common::SLPoint &sl_point) const
: check if a box/point is on lane along reference line
void AddSpeedLimit(double start_s, double end_s, double speed_limit)
void GetLaneBoundaryType(const double s, hdmap::LaneBoundaryType::Type *const left_boundary_type, hdmap::LaneBoundaryType::Type *const right_boundary_type) const
ReferencePoint GetReferencePoint(const double s) const
std::vector< hdmap::LaneSegment > GetLaneSegments(const double start_s, const double end_s) const
void SetEgoPosition(common::math::Vec2d ego_pos)
std::pair< std::array< double, 3 >, std::array< double, 3 > > ToFrenetFrame(const common::TrajectoryPoint &traj_point) const
bool XYToSL(const XYPoint &xy, common::SLPoint *const sl_point) const
double GetDrivingWidth(const SLBoundary &sl_boundary) const
bool IsOnLane(const XYPoint &xy) const
size_t GetNearestReferenceIndex(const double s) const
bool GetSLBoundary(const common::math::Box2d &box, SLBoundary *const sl_boundary, double warm_start_s=-1.0) const
Get the SL Boundary of the box.
bool Stitch(const ReferenceLine &other)
Stitch current reference line with the other reference line The stitching strategy is to use current ...
void SetPriority(uint32_t priority)
bool GetRoadWidth(const double s, double *const road_left_width, double *const road_right_width) const
void GetLaneFromS(const double s, std::vector< hdmap::LaneInfoConstPtr > *lanes) const
bool SLToXY(const common::SLPoint &sl_point, common::math::Vec2d *const xy_point) const
ReferenceLine(const ReferenceLine &reference_line)=default
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point, double warm_start_s=-1.0) const
Transvert Cartesian coordinates to Frenet.
std::vector< ReferencePoint > GetReferencePoints(double start_s, double end_s) const
hdmap::Road::Type GetRoadType(const double s) const
ReferencePoint GetNearestReferencePoint(const common::math::Vec2d &xy) const
bool HasOverlap(const common::math::Box2d &box) const
check if any part of the box has overlap with the road.
common::FrenetFramePoint GetFrenetPoint(const common::PathPoint &path_point) const
double GetSpeedLimitFromS(const double s) const
bool IsBlockRoad(const common::math::Box2d &box2d, double gap) const
Check if a box is blocking the road surface.
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
const std::vector< ReferencePoint > & reference_points() const
bool GetOffsetToMap(const double s, double *l_offset) const
ReferenceLine(const Iterator begin, const Iterator end)
Planning module main class.
class register implement
Definition arena_queue.h:37
Definition future.h:29
Defines the Vec2d class.