Apollo  6.0
Open source self driving car software
reference_line_provider.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 
23 #pragma once
24 
25 #include <list>
26 #include <memory>
27 #include <queue>
28 #include <string>
29 #include <unordered_set>
30 #include <vector>
31 
32 #include "cyber/cyber.h"
35 #include "modules/common/vehicle_state/proto/vehicle_state.pb.h"
38 #include "modules/map/relative_map/proto/navigation.pb.h"
41 #include "modules/planning/proto/planning_config.pb.h"
46 
51 namespace apollo {
52 namespace planning {
53 
60  public:
61  ReferenceLineProvider() = default;
63  const common::VehicleStateProvider* vehicle_state_provider,
64  const hdmap::HDMap* base_map,
65  const std::shared_ptr<relative_map::MapMsg>& relative_map = nullptr);
66 
71 
72  bool UpdateRoutingResponse(const routing::RoutingResponse& routing);
73 
74  void UpdateVehicleState(const common::VehicleState& vehicle_state);
75 
76  bool Start();
77 
78  void Stop();
79 
80  bool GetReferenceLines(std::list<ReferenceLine>* reference_lines,
81  std::list<hdmap::RouteSegments>* segments);
82 
83  double LastTimeDelay();
84 
85  std::vector<routing::LaneWaypoint> FutureRouteWaypoints();
86 
87  bool UpdatedReferenceLine() { return is_reference_line_updated_.load(); }
88 
89  private:
96  bool CreateReferenceLine(std::list<ReferenceLine>* reference_lines,
97  std::list<hdmap::RouteSegments>* segments);
98 
103  void UpdateReferenceLine(
104  const std::list<ReferenceLine>& reference_lines,
105  const std::list<hdmap::RouteSegments>& route_segments);
106 
107  void GenerateThread();
108  void IsValidReferenceLine();
109  void PrioritzeChangeLane(std::list<hdmap::RouteSegments>* route_segments);
110 
111  bool CreateRouteSegments(const common::VehicleState& vehicle_state,
112  std::list<hdmap::RouteSegments>* segments);
113 
114  bool IsReferenceLineSmoothValid(const ReferenceLine& raw,
115  const ReferenceLine& smoothed) const;
116 
117  bool SmoothReferenceLine(const ReferenceLine& raw_reference_line,
118  ReferenceLine* reference_line);
119 
120  bool SmoothPrefixedReferenceLine(const ReferenceLine& prefix_ref,
121  const ReferenceLine& raw_ref,
122  ReferenceLine* reference_line);
123 
124  void GetAnchorPoints(const ReferenceLine& reference_line,
125  std::vector<AnchorPoint>* anchor_points) const;
126 
127  bool SmoothRouteSegment(const hdmap::RouteSegments& segments,
128  ReferenceLine* reference_line);
129 
134  bool ExtendReferenceLine(const common::VehicleState& state,
135  hdmap::RouteSegments* segments,
136  ReferenceLine* reference_line);
137 
138  AnchorPoint GetAnchorPoint(const ReferenceLine& reference_line,
139  double s) const;
140 
141  bool GetReferenceLinesFromRelativeMap(
142  std::list<ReferenceLine>* reference_lines,
143  std::list<hdmap::RouteSegments>* segments);
144 
149  bool GetNearestWayPointFromNavigationPath(
150  const common::VehicleState& state,
151  const std::unordered_set<std::string>& navigation_lane_ids,
152  hdmap::LaneWaypoint* waypoint);
153 
154  bool Shrink(const common::SLPoint& sl, ReferenceLine* ref,
155  hdmap::RouteSegments* segments);
156 
157  private:
158  bool is_initialized_ = false;
159  std::atomic<bool> is_stop_{false};
160 
161  std::unique_ptr<ReferenceLineSmoother> smoother_;
162  ReferenceLineSmootherConfig smoother_config_;
163 
164  std::mutex pnc_map_mutex_;
165  std::unique_ptr<hdmap::PncMap> pnc_map_;
166 
167  // Used in Navigation mode
168  std::shared_ptr<relative_map::MapMsg> relative_map_;
169 
170  std::mutex vehicle_state_mutex_;
171  common::VehicleState vehicle_state_;
172 
173  std::mutex routing_mutex_;
174  routing::RoutingResponse routing_;
175  bool has_routing_ = false;
176 
177  std::mutex reference_lines_mutex_;
178  std::list<ReferenceLine> reference_lines_;
179  std::list<hdmap::RouteSegments> route_segments_;
180  double last_calculation_time_ = 0.0;
181 
182  std::queue<std::list<ReferenceLine>> reference_line_history_;
183  std::queue<std::list<hdmap::RouteSegments>> route_segments_history_;
184 
185  std::future<void> task_future_;
186 
187  std::atomic<bool> is_reference_line_updated_{true};
188 
189  const common::VehicleStateProvider* vehicle_state_provider_ = nullptr;
190 };
191 
192 } // namespace planning
193 } // namespace apollo
class RouteSegments
Definition: route_segments.h:50
The class of vehicle state. It includes basic information and computation about the state of the vehi...
Definition: vehicle_state_provider.h:46
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Planning module main class. It processes GPS and IMU as input, to generate planning info...
void UpdateVehicleState(const common::VehicleState &vehicle_state)
bool UpdateRoutingResponse(const routing::RoutingResponse &routing)
bool UpdatedReferenceLine()
Definition: reference_line_provider.h:87
Definition: reference_line_smoother.h:31
Defines the Factory class.
High-precision map loader interface.
Definition: hdmap.h:53
Definition: reference_line.h:39
bool GetReferenceLines(std::list< ReferenceLine > *reference_lines, std::list< hdmap::RouteSegments > *segments)
~ReferenceLineProvider()
Default destructor.
The class of ReferenceLineProvider. It provides smoothed reference line to planning.
Definition: reference_line_provider.h:59
Some util functions.
std::vector< routing::LaneWaypoint > FutureRouteWaypoints()
Definition: path.h:39