rs_path.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*******************************************************************************
  2. * Software License Agreement (BSD License)
  3. *
  4. * Copyright (c) 2022 Zhang Zhimeng
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  20. * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  22. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  25. * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. ******************************************************************************/
  27. #ifndef HYBRID_A_STAR_RS_PATH_H_COMBINE
  28. #define HYBRID_A_STAR_RS_PATH_H_COMBINE
  29. #include "combine_planning/type.h"
  30. #include <cmath>
  31. #include <limits>
  32. #include <vector>
  33. #include <Eigen/Core>
  34. namespace combine_planning_ns
  35. {
  36. // 模板类型定义
  37. // template<int dim>
  38. // using TypeVectorVecd = typename std::vector<Eigen::Matrix<double, dim, 1>,
  39. // Eigen::aligned_allocator<Eigen::Matrix<double, dim, 1>>>;
  40. /*!
  41. * Refer to this paper:
  42. * 1990 Optimal paths for a car that goes both forwards and backwards. J. A. Reeds, L. A. Shepp. Pacific J.
  43. *
  44. * Notes: There are many notation errors in this paper, and there are many formula derivation errors.
  45. * When reading the paper, please note that the errors! Errors mainly concentrated in Section 8.
  46. */
  47. class RSPath
  48. {
  49. public:
  50. // double turning_radius_ = 1.0;
  51. // RSPath() = delete;
  52. // explicit RSPath(double turning_radius = 1.0);
  53. enum RSPathSegmentType
  54. {
  55. N = 0,
  56. L = 1,
  57. S = 2,
  58. R = 3
  59. };
  60. static const RSPathSegmentType RS_path_segment_type[18][5];
  61. struct RSPathData
  62. {
  63. public:
  64. explicit RSPathData(const RSPathSegmentType *type = RS_path_segment_type[0],
  65. double t = std::numeric_limits<double>::max(),
  66. double u = 0.0, double v = 0.0, double w = 0.0, double x = 0.0) : type_(type)
  67. {
  68. length_[0] = t;
  69. length_[1] = u;
  70. length_[2] = v;
  71. length_[3] = w;
  72. length_[4] = x;
  73. total_length_ = std::fabs(length_[0]) + std::fabs(length_[1]) + std::fabs(length_[2]) + std::fabs(length_[3]) + std::fabs(length_[4]);
  74. }
  75. double Length() const
  76. {
  77. return total_length_;
  78. }
  79. public:
  80. double length_[5]{};
  81. const RSPathSegmentType *type_;
  82. private:
  83. double total_length_;
  84. };
  85. /*!
  86. * Calculate the actual distance from (x_0, y_0, yaw_0) to (x_1, y_1, yaw_1)
  87. * @param x_0
  88. * @param y_0
  89. * @param yaw_0
  90. * @param x_1
  91. * @param y_1
  92. * @param yaw_1
  93. * @return
  94. */
  95. double Distance(double x_0, double y_0, double yaw_0,
  96. double x_1, double y_1, double yaw_1);
  97. /*!
  98. * Get a reed shepp path
  99. * @param start_state start state including position and yaw
  100. * @param goal_state goal state including position and yaw
  101. * @param step_size actual step size for collision detection
  102. * @return Discrete points of reed shepp path, including position and yaw
  103. */
  104. TypeVectorVecd<3> GetRSPath(const Eigen::Vector3d &start_state, const Eigen::Vector3d &goal_state, double step_size, double &length);
  105. RSPathData GetRSPath(double x_0, double y_0, double yaw_0,
  106. double x_1, double y_1, double yaw_1);
  107. RSPathData GetRSPath(double x, double y, double phi);
  108. private:
  109. static void CSC(double x, double y, double phi, RSPathData &path);
  110. void CCC(double x, double y, double phi, RSPathData &path);
  111. static void CCCC(double x, double y, double phi, RSPathData &path);
  112. static void CCSC(double x, double y, double phi, RSPathData &path);
  113. static void CCSCC(double x, double y, double phi, RSPathData &path);
  114. static inline double Mod2Pi(double x);
  115. static inline void Polar(double x, double y, double &r, double &theta);
  116. static inline void TauOmega(double u, double v, double xi, double eta, double phi, double &tau, double &omega);
  117. // Paper P390, formula 8.1
  118. static inline bool LpSpLp(double x, double y, double phi, double &t, double &u, double &v);
  119. // Paper P390, formula 8.2
  120. static inline bool LpSpRp(double x, double y, double phi, double &t, double &u, double &v);
  121. // Paper P390 formula 8.3 and 8.4.
  122. // There is an error in the deduction of the formula in the paper.
  123. // It can be deduced by itself according to the inscribed circle.
  124. static inline bool LpRmL(double x, double y, double phi, double &t, double &u, double &v);
  125. // Paper P391 formula 8.7
  126. static inline bool LpRupLumRm(double x, double y, double phi, double &t, double &u, double &v);
  127. // Paper P391 formula 8.8
  128. static inline bool LpRumLumRp(double x, double y, double phi, double &t, double &u, double &v);
  129. // Paper P391 formula 8.9
  130. static inline bool LpRmSmLm(double x, double y, double phi, double &t, double &u, double &v);
  131. // Paper P391 formula 8.10
  132. static inline bool LpRmSmRm(double x, double y, double phi, double &t, double &u, double &v);
  133. // Paper P391 formula 8.11
  134. // There is an error in the deduction of the formula in the paper.
  135. // It can be deduced by itself according to the inscribed circle.
  136. static inline bool LpRmSLmRp(double x, double y, double phi, double &t, double &u, double &v);
  137. // private:
  138. // double turning_radius_ = 1.0;
  139. };
  140. };
  141. #endif // HYBRID_A_STAR_RS_PATH_H