Apollo  6.0
Open source self driving car software
hybrid_a_star.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 
17 /*
18  * @file
19  */
20 
21 #pragma once
22 
23 #include <algorithm>
24 #include <memory>
25 #include <queue>
26 #include <string>
27 #include <unordered_map>
28 #include <utility>
29 #include <vector>
30 
31 #include "cyber/common/log.h"
32 #include "cyber/common/macros.h"
33 #include "cyber/time/clock.h"
34 #include "modules/common/configs/proto/vehicle_config.pb.h"
42 #include "modules/planning/proto/planner_open_space_config.pb.h"
43 
44 namespace apollo {
45 namespace planning {
46 
48  std::vector<double> x;
49  std::vector<double> y;
50  std::vector<double> phi;
51  std::vector<double> v;
52  std::vector<double> a;
53  std::vector<double> steer;
54  std::vector<double> accumulated_s;
55 };
56 
57 class HybridAStar {
58  public:
59  explicit HybridAStar(const PlannerOpenSpaceConfig& open_space_conf);
60  virtual ~HybridAStar() = default;
61  bool Plan(double sx, double sy, double sphi, double ex, double ey,
62  double ephi, const std::vector<double>& XYbounds,
63  const std::vector<std::vector<common::math::Vec2d>>&
64  obstacles_vertices_vec,
65  HybridAStartResult* result);
66  bool TrajectoryPartition(const HybridAStartResult& result,
67  std::vector<HybridAStartResult>* partitioned_result);
68 
69  private:
70  bool AnalyticExpansion(std::shared_ptr<Node3d> current_node);
71  // check collision and validity
72  bool ValidityCheck(std::shared_ptr<Node3d> node);
73  // check Reeds Shepp path collision and validity
74  bool RSPCheck(const std::shared_ptr<ReedSheppPath> reeds_shepp_to_end);
75  // load the whole RSP as nodes and add to the close set
76  std::shared_ptr<Node3d> LoadRSPinCS(
77  const std::shared_ptr<ReedSheppPath> reeds_shepp_to_end,
78  std::shared_ptr<Node3d> current_node);
79  std::shared_ptr<Node3d> Next_node_generator(
80  std::shared_ptr<Node3d> current_node, size_t next_node_index);
81  void CalculateNodeCost(std::shared_ptr<Node3d> current_node,
82  std::shared_ptr<Node3d> next_node);
83  double TrajCost(std::shared_ptr<Node3d> current_node,
84  std::shared_ptr<Node3d> next_node);
85  double HoloObstacleHeuristic(std::shared_ptr<Node3d> next_node);
86  bool GetResult(HybridAStartResult* result);
87  bool GetTemporalProfile(HybridAStartResult* result);
88  bool GenerateSpeedAcceleration(HybridAStartResult* result);
89  bool GenerateSCurveSpeedAcceleration(HybridAStartResult* result);
90 
91  private:
92  PlannerOpenSpaceConfig planner_open_space_config_;
93  common::VehicleParam vehicle_param_ =
95  size_t next_node_num_ = 0;
96  double max_steer_angle_ = 0.0;
97  double step_size_ = 0.0;
98  double xy_grid_resolution_ = 0.0;
99  double delta_t_ = 0.0;
100  double traj_forward_penalty_ = 0.0;
101  double traj_back_penalty_ = 0.0;
102  double traj_gear_switch_penalty_ = 0.0;
103  double traj_steer_penalty_ = 0.0;
104  double traj_steer_change_penalty_ = 0.0;
105  double heu_rs_forward_penalty_ = 0.0;
106  double heu_rs_back_penalty_ = 0.0;
107  double heu_rs_gear_switch_penalty_ = 0.0;
108  double heu_rs_steer_penalty_ = 0.0;
109  double heu_rs_steer_change_penalty_ = 0.0;
110  std::vector<double> XYbounds_;
111  std::shared_ptr<Node3d> start_node_;
112  std::shared_ptr<Node3d> end_node_;
113  std::shared_ptr<Node3d> final_node_;
114  std::vector<std::vector<common::math::LineSegment2d>>
115  obstacles_linesegments_vec_;
116 
117  struct cmp {
118  bool operator()(const std::pair<std::string, double>& left,
119  const std::pair<std::string, double>& right) const {
120  return left.second >= right.second;
121  }
122  };
123  std::priority_queue<std::pair<std::string, double>,
124  std::vector<std::pair<std::string, double>>, cmp>
125  open_pq_;
126  std::unordered_map<std::string, std::shared_ptr<Node3d>> open_set_;
127  std::unordered_map<std::string, std::shared_ptr<Node3d>> close_set_;
128  std::unique_ptr<ReedShepp> reed_shepp_generator_;
129  std::unique_ptr<GridSearch> grid_a_star_heuristic_generator_;
130 };
131 
132 } // namespace planning
133 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::vector< double > phi
Definition: hybrid_a_star.h:50
std::vector< double > v
Definition: hybrid_a_star.h:51
Planning module main class. It processes GPS and IMU as input, to generate planning info...
Definition: hybrid_a_star.h:57
std::vector< double > accumulated_s
Definition: hybrid_a_star.h:54
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Math-related util functions.
std::vector< double > y
Definition: hybrid_a_star.h:49
Definition: hybrid_a_star.h:47
std::vector< double > steer
Definition: hybrid_a_star.h:53
std::vector< double > a
Definition: hybrid_a_star.h:52
std::vector< double > x
Definition: hybrid_a_star.h:48