Apollo  6.0
Open source self driving car software
reeds_shepp_path.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 <limits>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 #include <omp.h>
30 
31 #include "cyber/common/log.h"
32 #include "cyber/common/macros.h"
33 #include "modules/common/configs/proto/vehicle_config.pb.h"
37 #include "modules/planning/proto/planner_open_space_config.pb.h"
38 
39 namespace apollo {
40 namespace planning {
41 
42 struct ReedSheppPath {
43  std::vector<double> segs_lengths;
44  std::vector<char> segs_types;
45  double total_length = 0.0;
46  std::vector<double> x;
47  std::vector<double> y;
48  std::vector<double> phi;
49  // true for driving forward and false for driving backward
50  std::vector<bool> gear;
51 };
52 
53 struct RSPParam {
54  bool flag = false;
55  double t = 0.0;
56  double u = 0.0;
57  double v = 0.0;
58 };
59 
60 class ReedShepp {
61  public:
62  ReedShepp(const common::VehicleParam& vehicle_param,
63  const PlannerOpenSpaceConfig& open_space_conf);
64  virtual ~ReedShepp() = default;
65  // Pick the shortest path from all possible combination of movement primitives
66  // by Reed Shepp
67  bool ShortestRSP(const std::shared_ptr<Node3d> start_node,
68  const std::shared_ptr<Node3d> end_node,
69  std::shared_ptr<ReedSheppPath> optimal_path);
70 
71  protected:
72  // Generate all possible combination of movement primitives by Reed Shepp and
73  // interpolate them
74  bool GenerateRSPs(const std::shared_ptr<Node3d> start_node,
75  const std::shared_ptr<Node3d> end_node,
76  std::vector<ReedSheppPath>* all_possible_paths);
77  // Set the general profile of the movement primitives
78  bool GenerateRSP(const std::shared_ptr<Node3d> start_node,
79  const std::shared_ptr<Node3d> end_node,
80  std::vector<ReedSheppPath>* all_possible_paths);
81  // Set the general profile of the movement primitives, parallel implementation
82  bool GenerateRSPPar(const std::shared_ptr<Node3d> start_node,
83  const std::shared_ptr<Node3d> end_node,
84  std::vector<ReedSheppPath>* all_possible_paths);
85  // Set local exact configurations profile of each movement primitive
86  bool GenerateLocalConfigurations(const std::shared_ptr<Node3d> start_node,
87  const std::shared_ptr<Node3d> end_node,
88  ReedSheppPath* shortest_path);
89  // Interpolation usde in GenetateLocalConfiguration
90  void Interpolation(const int index, const double pd, const char m,
91  const double ox, const double oy, const double ophi,
92  std::vector<double>* px, std::vector<double>* py,
93  std::vector<double>* pphi, std::vector<bool>* pgear);
94  // motion primitives combination setup function
95  bool SetRSP(const int size, const double* lengths, const char* types,
96  std::vector<ReedSheppPath>* all_possible_paths);
97  // setRSP parallel version
98  bool SetRSPPar(const int size, const double* lengths,
99  const std::string& types,
100  std::vector<ReedSheppPath>* all_possible_paths, const int idx);
101  // Six different combination of motion primitive in Reed Shepp path used in
102  // GenerateRSP()
103  bool SCS(const double x, const double y, const double phi,
104  std::vector<ReedSheppPath>* all_possible_paths);
105  bool CSC(const double x, const double y, const double phi,
106  std::vector<ReedSheppPath>* all_possible_paths);
107  bool CCC(const double x, const double y, const double phi,
108  std::vector<ReedSheppPath>* all_possible_paths);
109  bool CCCC(const double x, const double y, const double phi,
110  std::vector<ReedSheppPath>* all_possible_paths);
111  bool CCSC(const double x, const double y, const double phi,
112  std::vector<ReedSheppPath>* all_possible_paths);
113  bool CCSCC(const double x, const double y, const double phi,
114  std::vector<ReedSheppPath>* all_possible_paths);
115  // different options for different combination of motion primitives
116  void LSL(const double x, const double y, const double phi, RSPParam* param);
117  void LSR(const double x, const double y, const double phi, RSPParam* param);
118  void LRL(const double x, const double y, const double phi, RSPParam* param);
119  void SLS(const double x, const double y, const double phi, RSPParam* param);
120  void LRLRn(const double x, const double y, const double phi, RSPParam* param);
121  void LRLRp(const double x, const double y, const double phi, RSPParam* param);
122  void LRSR(const double x, const double y, const double phi, RSPParam* param);
123  void LRSL(const double x, const double y, const double phi, RSPParam* param);
124  void LRSLR(const double x, const double y, const double phi, RSPParam* param);
125  std::pair<double, double> calc_tau_omega(const double u, const double v,
126  const double xi, const double eta,
127  const double phi);
128 
129  protected:
130  common::VehicleParam vehicle_param_;
131  PlannerOpenSpaceConfig planner_open_space_config_;
132  double max_kappa_;
133 };
134 } // namespace planning
135 } // namespace apollo
Definition: reeds_shepp_path.h:53
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::vector< double > x
Definition: reeds_shepp_path.h:46
Planning module main class. It processes GPS and IMU as input, to generate planning info...
double total_length
Definition: reeds_shepp_path.h:45
std::vector< double > phi
Definition: reeds_shepp_path.h:48
PlannerOpenSpaceConfig planner_open_space_config_
Definition: reeds_shepp_path.h:131
std::vector< char > segs_types
Definition: reeds_shepp_path.h:44
double max_kappa_
Definition: reeds_shepp_path.h:132
std::vector< double > y
Definition: reeds_shepp_path.h:47
std::vector< double > segs_lengths
Definition: reeds_shepp_path.h:43
Definition: reeds_shepp_path.h:42
Math-related util functions.
common::VehicleParam vehicle_param_
Definition: reeds_shepp_path.h:130
Definition: reeds_shepp_path.h:60
std::vector< bool > gear
Definition: reeds_shepp_path.h:50