Apollo  6.0
Open source self driving car software
reference_line.h
Go to the documentation of this file.
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 
28 #include "modules/common/proto/pnc_point.pb.h"
30 #include "modules/map/proto/map.pb.h"
31 #include "modules/map/proto/map_geometry.pb.h"
32 #include "modules/planning/proto/sl_boundary.pb.h"
34 #include "modules/routing/proto/routing.pb.h"
35 
36 namespace apollo {
37 namespace planning {
38 
40  public:
41  ReferenceLine() = default;
42  explicit ReferenceLine(const ReferenceLine& reference_line) = default;
43  template <typename Iterator>
44  ReferenceLine(const Iterator begin, const Iterator end)
45  : reference_points_(begin, end),
46  map_path_(std::move(std::vector<hdmap::MapPathPoint>(begin, end))) {}
47  explicit ReferenceLine(const std::vector<ReferencePoint>& reference_points);
48  explicit ReferenceLine(const hdmap::Path& hdmap_path);
49 
72  bool Stitch(const ReferenceLine& other);
73 
74  bool Segment(const common::math::Vec2d& point, const double distance_backward,
75  const double distance_forward);
76 
77  bool Segment(const double s, const double distance_backward,
78  const double distance_forward);
79 
80  const hdmap::Path& map_path() const;
81  const std::vector<ReferencePoint>& reference_points() const;
82 
83  ReferencePoint GetReferencePoint(const double s) const;
84 
85  common::FrenetFramePoint GetFrenetPoint(
86  const common::PathPoint& path_point) const;
87 
88  std::pair<std::array<double, 3>, std::array<double, 3>> ToFrenetFrame(
89  const common::TrajectoryPoint& traj_point) const;
90 
91  std::vector<ReferencePoint> GetReferencePoints(double start_s,
92  double end_s) const;
93 
94  size_t GetNearestReferenceIndex(const double s) const;
95 
97 
98  std::vector<hdmap::LaneSegment> GetLaneSegments(const double start_s,
99  const double end_s) const;
100 
101  ReferencePoint GetNearestReferencePoint(const double s) const;
102 
103  ReferencePoint GetReferencePoint(const double x, const double y) const;
104 
106  const double start_s, const double end_s,
107  SLBoundary* const sl_boundary) const;
108  bool GetSLBoundary(const common::math::Box2d& box,
109  SLBoundary* const sl_boundary) const;
110  bool GetSLBoundary(const hdmap::Polygon& polygon,
111  SLBoundary* const sl_boundary) const;
112 
113  bool SLToXY(const common::SLPoint& sl_point,
114  common::math::Vec2d* const xy_point) const;
115  bool XYToSL(const common::math::Vec2d& xy_point,
116  common::SLPoint* const sl_point) const;
117  template <class XYPoint>
118  bool XYToSL(const XYPoint& xy, common::SLPoint* const sl_point) const {
119  return XYToSL(common::math::Vec2d(xy.x(), xy.y()), sl_point);
120  }
121 
122  bool GetLaneWidth(const double s, double* const lane_left_width,
123  double* const lane_right_width) const;
124 
125  bool GetOffsetToMap(const double s, double* l_offset) const;
126 
127  bool GetRoadWidth(const double s, double* const road_left_width,
128  double* const road_right_width) const;
129 
130  hdmap::Road::Type GetRoadType(const double s) const;
131 
132  void GetLaneFromS(const double s,
133  std::vector<hdmap::LaneInfoConstPtr>* lanes) const;
134 
135  double GetDrivingWidth(const SLBoundary& sl_boundary) const;
136 
140  bool IsOnLane(const common::SLPoint& sl_point) const;
141  bool IsOnLane(const common::math::Vec2d& vec2d_point) const;
142  template <class XYPoint>
143  bool IsOnLane(const XYPoint& xy) const {
144  return IsOnLane(common::math::Vec2d(xy.x(), xy.y()));
145  }
146  bool IsOnLane(const SLBoundary& sl_boundary) const;
147 
152  bool IsOnRoad(const common::SLPoint& sl_point) const;
153  bool IsOnRoad(const common::math::Vec2d& vec2d_point) const;
154  bool IsOnRoad(const SLBoundary& sl_boundary) const;
155 
164  bool IsBlockRoad(const common::math::Box2d& box2d, double gap) const;
165 
169  bool HasOverlap(const common::math::Box2d& box) const;
170 
171  double Length() const { return map_path_.length(); }
172 
173  std::string DebugString() const;
174 
175  double GetSpeedLimitFromS(const double s) const;
176 
177  void AddSpeedLimit(double start_s, double end_s, double speed_limit);
178 
179  uint32_t GetPriority() const { return priority_; }
180 
181  void SetPriority(uint32_t priority) { priority_ = priority; }
182 
183  const hdmap::Path& GetMapPath() const { return map_path_; }
184 
185  private:
204  static ReferencePoint Interpolate(const ReferencePoint& p0, const double s0,
205  const ReferencePoint& p1, const double s1,
206  const double s);
207  ReferencePoint InterpolateWithMatchedIndex(
208  const ReferencePoint& p0, const double s0, const ReferencePoint& p1,
209  const double s1, const hdmap::InterpolatedIndex& index) const;
210 
211  static double FindMinDistancePoint(const ReferencePoint& p0, const double s0,
212  const ReferencePoint& p1, const double s1,
213  const double x, const double y);
214 
215  private:
216  struct SpeedLimit {
217  double start_s = 0.0;
218  double end_s = 0.0;
219  double speed_limit = 0.0; // unit m/s
220  SpeedLimit() = default;
221  SpeedLimit(double _start_s, double _end_s, double _speed_limit)
222  : start_s(_start_s), end_s(_end_s), speed_limit(_speed_limit) {}
223  };
227  std::vector<SpeedLimit> speed_limit_;
228  std::vector<ReferencePoint> reference_points_;
229  hdmap::Path map_path_;
230  uint32_t priority_ = 0;
231 };
232 
233 } // namespace planning
234 } // namespace apollo
double Length() const
Definition: reference_line.h:171
size_t GetNearestReferenceIndex(const double s) const
void GetLaneFromS(const double s, std::vector< hdmap::LaneInfoConstPtr > *lanes) const
bool Segment(const common::math::Vec2d &point, const double distance_backward, const double distance_forward)
ReferencePoint GetReferencePoint(const double s) 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 GetSLBoundary(const common::math::Box2d &box, SLBoundary *const sl_boundary) const
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point) const
Defines the Vec2d class.
double GetSpeedLimitFromS(const double s) const
hdmap::Road::Type GetRoadType(const double s) const
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: future.h:29
Planning module main class. It processes GPS and IMU as input, to generate planning info...
ReferenceLine(const Iterator begin, const Iterator end)
Definition: reference_line.h:44
std::string DebugString() const
Definition: reference_point.h:32
const hdmap::Path & map_path() const
bool GetRoadWidth(const double s, double *const road_left_width, double *const road_right_width) const
std::vector< ReferencePoint > GetReferencePoints(double start_s, double end_s) const
double GetDrivingWidth(const SLBoundary &sl_boundary) const
Rectangular (undirected) bounding box in 2-D.
Definition: box2d.h:52
Definition: path.h:208
bool GetApproximateSLBoundary(const common::math::Box2d &box, const double start_s, const double end_s, SLBoundary *const sl_boundary) const
const std::vector< ReferencePoint > & reference_points() const
bool SLToXY(const common::SLPoint &sl_point, common::math::Vec2d *const xy_point) const
Implements a class of 2-dimensional vectors.
Definition: vec2d.h:42
Definition: path.h:215
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)
const hdmap::Path & GetMapPath() const
Definition: reference_line.h:183
ReferencePoint GetNearestReferencePoint(const common::math::Vec2d &xy) const
uint32_t GetPriority() const
Definition: reference_line.h:179
std::pair< std::array< double, 3 >, std::array< double, 3 > > ToFrenetFrame(const common::TrajectoryPoint &traj_point) const
bool Stitch(const ReferenceLine &other)
Definition: reference_line.h:39
double length() const
Definition: path.h:284
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
bool GetOffsetToMap(const double s, double *l_offset) 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
void SetPriority(uint32_t priority)
Definition: reference_line.h:181
bool IsOnLane(const XYPoint &xy) const
Definition: reference_line.h:143
std::vector< hdmap::LaneSegment > GetLaneSegments(const double start_s, const double end_s) const
bool XYToSL(const XYPoint &xy, common::SLPoint *const sl_point) const
Definition: reference_line.h:118
bool IsBlockRoad(const common::math::Box2d &box2d, double gap) const
Check if a box is blocking the road surface. The criteria is to check whether the remaining space on ...