Apollo  6.0
Open source self driving car software
pnc_map.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 <list>
24 #include <string>
25 #include <unordered_set>
26 #include <vector>
27 
28 #include "gflags/gflags.h"
29 #include "gtest/gtest_prod.h"
30 
31 #include "modules/common/vehicle_state/proto/vehicle_state.pb.h"
32 #include "modules/routing/proto/routing.pb.h"
33 
37 
38 DECLARE_double(look_backward_distance);
39 DECLARE_double(look_forward_short_distance);
40 DECLARE_double(look_forward_long_distance);
41 
42 namespace apollo {
43 namespace hdmap {
44 
45 class PncMap {
46  public:
47  virtual ~PncMap() = default;
48  explicit PncMap(const HDMap *hdmap);
49 
50  const hdmap::HDMap *hdmap() const;
51 
52  bool UpdateRoutingResponse(const routing::RoutingResponse &routing_response);
53 
54  const routing::RoutingResponse &routing_response() const;
55 
56  static double LookForwardDistance(const double velocity);
57 
58  bool GetRouteSegments(const common::VehicleState &vehicle_state,
59  const double backward_length,
60  const double forward_length,
61  std::list<RouteSegments> *const route_segments);
65  bool GetRouteSegments(const common::VehicleState &vehicle_state,
66  std::list<RouteSegments> *const route_segments);
67 
71  bool IsNewRouting(const routing::RoutingResponse &routing_response) const;
72  static bool IsNewRouting(const routing::RoutingResponse &prev,
73  const routing::RoutingResponse &routing_response);
74 
75  bool ExtendSegments(const RouteSegments &segments,
76  const common::PointENU &point, double look_forward,
77  double look_backward, RouteSegments *extended_segments);
78 
79  bool ExtendSegments(const RouteSegments &segments, double start_s,
80  double end_s,
81  RouteSegments *const truncated_segments) const;
82 
83  std::vector<routing::LaneWaypoint> FutureRouteWaypoints() const;
84 
85  private:
86  bool UpdateVehicleState(const common::VehicleState &vehicle_state);
93  int GetWaypointIndex(const LaneWaypoint &waypoint) const;
94 
95  bool GetNearestPointFromRouting(const common::VehicleState &point,
96  LaneWaypoint *waypoint) const;
97 
98  bool PassageToSegments(routing::Passage passage,
99  RouteSegments *segments) const;
100 
101  bool ProjectToSegments(const common::PointENU &point_enu,
102  const RouteSegments &segments,
103  LaneWaypoint *waypoint) const;
104 
105  static bool ValidateRouting(const routing::RoutingResponse &routing);
106 
107  static void AppendLaneToPoints(LaneInfoConstPtr lane, const double start_s,
108  const double end_s,
109  std::vector<MapPathPoint> *const points);
110 
111  LaneInfoConstPtr GetRoutePredecessor(LaneInfoConstPtr lane) const;
112  LaneInfoConstPtr GetRouteSuccessor(LaneInfoConstPtr lane) const;
113 
121  std::vector<int> GetNeighborPassages(const routing::RoadSegment &road,
122  int start_passage) const;
123 
129  LaneWaypoint ToLaneWaypoint(const routing::LaneWaypoint &waypoint) const;
130 
136  LaneSegment ToLaneSegment(const routing::LaneSegment &segment) const;
137 
147  void UpdateNextRoutingWaypointIndex(int cur_index);
148 
154  int SearchForwardWaypointIndex(int start, const LaneWaypoint &waypoint) const;
155  int SearchBackwardWaypointIndex(int start,
156  const LaneWaypoint &waypoint) const;
157 
158  void UpdateRoutingRange(int adc_index);
159 
160  private:
161  routing::RoutingResponse routing_;
162  struct RouteIndex {
163  LaneSegment segment;
164  std::array<int, 3> index;
165  };
166  std::vector<RouteIndex> route_indices_;
167  int range_start_ = 0;
168  int range_end_ = 0;
169  // routing ids in range
170  std::unordered_set<std::string> range_lane_ids_;
171  std::unordered_set<std::string> all_lane_ids_;
172 
176  struct WaypointIndex {
177  LaneWaypoint waypoint;
178  int index;
179  WaypointIndex(const LaneWaypoint &waypoint, int index)
180  : waypoint(waypoint), index(index) {}
181  };
182 
183  // return the segment of an index
184  int NextWaypointIndex(int index) const;
185 
186  std::vector<WaypointIndex> routing_waypoint_index_;
190  std::size_t next_routing_waypoint_index_ = 0;
191 
192  const hdmap::HDMap *hdmap_ = nullptr;
193  bool is_same_routing_ = false;
194 
198  common::VehicleState adc_state_;
202  int adc_route_index_ = -1;
206  LaneWaypoint adc_waypoint_;
207 
216  bool stop_for_destination_ = false;
217 
218  FRIEND_TEST(PncMapTest, UpdateRouting);
219  FRIEND_TEST(PncMapTest, GetNearestPointFromRouting);
220  FRIEND_TEST(PncMapTest, UpdateWaypointIndex);
221  FRIEND_TEST(PncMapTest, UpdateNextRoutingWaypointIndex);
222  FRIEND_TEST(PncMapTest, GetNeighborPassages);
223  FRIEND_TEST(PncMapTest, NextWaypointIndex);
224  FRIEND_TEST(PncMapTest, SearchForwardIndex_SearchBackwardIndex);
225 };
226 
227 } // namespace hdmap
228 } // namespace apollo
std::vector< routing::LaneWaypoint > FutureRouteWaypoints() const
static double LookForwardDistance(const double velocity)
class RouteSegments
Definition: route_segments.h:50
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
const hdmap::HDMap * hdmap() const
bool UpdateRoutingResponse(const routing::RoutingResponse &routing_response)
bool ExtendSegments(const RouteSegments &segments, const common::PointENU &point, double look_forward, double look_backward, RouteSegments *extended_segments)
Definition: path.h:74
Definition: pnc_map.h:45
PncMap(const HDMap *hdmap)
High-precision map loader interface.
Definition: hdmap.h:53
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
Definition: hdmap_common.h:125
bool IsNewRouting(const routing::RoutingResponse &routing_response) const
virtual ~PncMap()=default
DECLARE_double(look_backward_distance)
const routing::RoutingResponse & routing_response() const
Definition: path.h:39
bool GetRouteSegments(const common::VehicleState &vehicle_state, const double backward_length, const double forward_length, std::list< RouteSegments > *const route_segments)