Apollo  6.0
Open source self driving car software
dp_road_graph.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 "modules/common/proto/pnc_point.pb.h"
32 #include "modules/planning/proto/dp_poly_path_config.pb.h"
36 
37 namespace apollo {
38 namespace planning {
39 
40 class DpRoadGraph {
41  public:
42  DpRoadGraph(const DpPolyPathConfig &config,
43  const ReferenceLineInfo &reference_line_info,
44  const SpeedData &speed_data);
45 
46  ~DpRoadGraph() = default;
47 
48  bool FindPathTunnel(const common::TrajectoryPoint &init_point,
49  const std::vector<const Obstacle *> &obstacles,
50  PathData *const path_data);
51 
52  void SetDebugLogger(apollo::planning_internal::Debug *debug) {
53  planning_debug_ = debug;
54  }
55 
56  void SetWaypointSampler(WaypointSampler *waypoint_sampler) {
57  waypoint_sampler_.reset(waypoint_sampler);
58  }
59 
60  private:
64  struct DpRoadGraphNode {
65  public:
66  DpRoadGraphNode() = default;
67 
68  DpRoadGraphNode(const common::SLPoint point_sl,
69  const DpRoadGraphNode *node_prev)
70  : sl_point(point_sl), min_cost_prev_node(node_prev) {}
71 
72  DpRoadGraphNode(const common::SLPoint point_sl,
73  const DpRoadGraphNode *node_prev,
74  const ComparableCost &cost)
75  : sl_point(point_sl), min_cost_prev_node(node_prev), min_cost(cost) {}
76 
77  void UpdateCost(const DpRoadGraphNode *node_prev,
78  const QuinticPolynomialCurve1d &curve,
79  const ComparableCost &cost) {
80  if (cost <= min_cost) {
81  min_cost = cost;
82  min_cost_prev_node = node_prev;
83  min_cost_curve = curve;
84  }
85  }
86 
87  common::SLPoint sl_point;
88  const DpRoadGraphNode *min_cost_prev_node = nullptr;
89  ComparableCost min_cost = {true, true, true,
90  std::numeric_limits<double>::infinity(),
91  std::numeric_limits<double>::infinity()};
92  QuinticPolynomialCurve1d min_cost_curve;
93  };
94  bool GenerateMinCostPath(const std::vector<const Obstacle *> &obstacles,
95  std::vector<DpRoadGraphNode> *min_cost_path);
96 
97  bool IsValidCurve(const QuinticPolynomialCurve1d &curve) const;
98 
99  void GetCurveCost(TrajectoryCost trajectory_cost,
100  const QuinticPolynomialCurve1d &curve, const double start_s,
101  const double end_s, const uint32_t curr_level,
102  const uint32_t total_level, ComparableCost *cost);
103 
104  struct RoadGraphMessage {
105  RoadGraphMessage(const std::list<DpRoadGraphNode> &_prev_nodes,
106  const uint32_t _level, const uint32_t _total_level,
107  TrajectoryCost *_trajectory_cost, DpRoadGraphNode *_front,
108  DpRoadGraphNode *_cur_node)
109  : prev_nodes(_prev_nodes),
110  level(_level),
111  total_level(_total_level),
112  trajectory_cost(_trajectory_cost),
113  front(_front),
114  cur_node(_cur_node) {}
115  const std::list<DpRoadGraphNode> &prev_nodes;
116  const uint32_t level;
117  const uint32_t total_level;
118  TrajectoryCost *trajectory_cost = nullptr;
119  DpRoadGraphNode *front = nullptr;
120  DpRoadGraphNode *cur_node = nullptr;
121  };
122  void UpdateNode(const std::shared_ptr<RoadGraphMessage> &msg);
123 
124  private:
125  DpPolyPathConfig config_;
126  common::TrajectoryPoint init_point_;
127  const ReferenceLineInfo &reference_line_info_;
128  const ReferenceLine &reference_line_;
129  SpeedData speed_data_;
130  common::SLPoint init_sl_point_;
131  common::FrenetFramePoint init_frenet_frame_point_;
132  apollo::planning_internal::Debug *planning_debug_ = nullptr;
133 
134  std::unique_ptr<WaypointSampler> waypoint_sampler_;
135 };
136 
137 } // namespace planning
138 } // namespace apollo
void SetWaypointSampler(WaypointSampler *waypoint_sampler)
Definition: dp_road_graph.h:56
bool FindPathTunnel(const common::TrajectoryPoint &init_point, const std::vector< const Obstacle *> &obstacles, PathData *const path_data)
DpRoadGraph(const DpPolyPathConfig &config, const ReferenceLineInfo &reference_line_info, const SpeedData &speed_data)
Definition: waypoint_sampler.h:38
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: dp_road_graph.h:40
Planning module main class. It processes GPS and IMU as input, to generate planning info...
ReferenceLineInfo holds all data for one reference line.
Definition: reference_line_info.h:54
Definition: quintic_polynomial_curve1d.h:33
Definition: path_data.h:36
Definition: comparable_cost.h:26
Definition: reference_line.h:39
void SetDebugLogger(apollo::planning_internal::Debug *debug)
Definition: dp_road_graph.h:52
Definition: trajectory_cost.h:36
Definition: speed_data.h:30