dubins.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef DUBINS_H
  2. #define DUBINS_H
  3. typedef enum
  4. {
  5. LSL = 0,
  6. LSR = 1,
  7. RSL = 2,
  8. RSR = 3,
  9. RLR = 4,
  10. LRL = 5
  11. } DubinsPathType;
  12. typedef struct
  13. {
  14. /* the initial configuration */
  15. double qi[3];
  16. /* the lengths of the three segments */
  17. double param[3];
  18. /* model forward velocity / model angular velocity */
  19. double rho;
  20. /* the path type described */
  21. DubinsPathType type;
  22. } DubinsPath;
  23. #define EDUBOK (0) /* No error */
  24. #define EDUBCOCONFIGS (1) /* Colocated configurations */
  25. #define EDUBPARAM (2) /* Path parameterisitation error */
  26. #define EDUBBADRHO (3) /* the rho value is invalid */
  27. #define EDUBNOPATH (4) /* no connection between configurations with this word */
  28. /**
  29. * Callback function for path sampling
  30. *
  31. * @note the q parameter is a configuration
  32. * @note the t parameter is the distance along the path
  33. * @note the user_data parameter is forwarded from the caller
  34. * @note return non-zero to denote sampling should be stopped
  35. */
  36. typedef int (*DubinsPathSamplingCallback)(double q[3], double t, void* user_data);
  37. /**
  38. * Generate a path from an initial configuration to
  39. * a target configuration, with a specified maximum turning
  40. * radii
  41. *
  42. * A configuration is (x, y, theta), where theta is in radians, with zero
  43. * along the line x = 0, and counter-clockwise is positive
  44. *
  45. * @param path - the resultant path
  46. * @param q0 - a configuration specified as an array of x, y, theta
  47. * @param q1 - a configuration specified as an array of x, y, theta
  48. * @param rho - turning radius of the vehicle (forward velocity divided by maximum angular velocity)
  49. * @return - non-zero on error
  50. */
  51. int dubins_shortest_path(DubinsPath* path, double q0[3], double q1[3], double rho);
  52. /**
  53. * Generate a path with a specified word from an initial configuration to
  54. * a target configuration, with a specified turning radius
  55. *
  56. * @param path - the resultant path
  57. * @param q0 - a configuration specified as an array of x, y, theta
  58. * @param q1 - a configuration specified as an array of x, y, theta
  59. * @param rho - turning radius of the vehicle (forward velocity divided by maximum angular velocity)
  60. * @param pathType - the specific path type to use
  61. * @return - non-zero on error
  62. */
  63. int dubins_path(DubinsPath* path, double q0[3], double q1[3], double rho, DubinsPathType pathType);
  64. /**
  65. * Calculate the length of an initialised path
  66. *
  67. * @param path - the path to find the length of
  68. */
  69. double dubins_path_length(DubinsPath* path);
  70. /**
  71. * Return the length of a specific segment in an initialized path
  72. *
  73. * @param path - the path to find the length of
  74. * @param i - the segment you to get the length of (0-2)
  75. */
  76. double dubins_segment_length(DubinsPath* path, int i);
  77. /**
  78. * Return the normalized length of a specific segment in an initialized path
  79. *
  80. * @param path - the path to find the length of
  81. * @param i - the segment you to get the length of (0-2)
  82. */
  83. double dubins_segment_length_normalized( DubinsPath* path, int i );
  84. /**
  85. * Extract an integer that represents which path type was used
  86. *
  87. * @param path - an initialised path
  88. * @return - one of LSL, LSR, RSL, RSR, RLR or LRL
  89. */
  90. DubinsPathType dubins_path_type(DubinsPath* path);
  91. /**
  92. * Calculate the configuration along the path, using the parameter t
  93. *
  94. * @param path - an initialised path
  95. * @param t - a length measure, where 0 <= t < dubins_path_length(path)
  96. * @param q - the configuration result
  97. * @returns - non-zero if 't' is not in the correct range
  98. */
  99. int dubins_path_sample(DubinsPath* path, double t, double q[3]);
  100. /**
  101. * Walk along the path at a fixed sampling interval, calling the
  102. * callback function at each interval
  103. *
  104. * The sampling process continues until the whole path is sampled, or the callback returns a non-zero value
  105. *
  106. * @param path - the path to sample
  107. * @param stepSize - the distance along the path for subsequent samples
  108. * @param cb - the callback function to call for each sample
  109. * @param user_data - optional information to pass on to the callback
  110. *
  111. * @returns - zero on successful completion, or the result of the callback
  112. */
  113. int dubins_path_sample_many(DubinsPath* path,
  114. double stepSize,
  115. DubinsPathSamplingCallback cb,
  116. void* user_data);
  117. /**
  118. * Convenience function to identify the endpoint of a path
  119. *
  120. * @param path - an initialised path
  121. * @param q - the configuration result
  122. */
  123. int dubins_path_endpoint(DubinsPath* path, double q[3]);
  124. /**
  125. * Convenience function to extract a subset of a path
  126. *
  127. * @param path - an initialised path
  128. * @param t - a length measure, where 0 < t < dubins_path_length(path)
  129. * @param newpath - the resultant path
  130. */
  131. int dubins_extract_subpath(DubinsPath* path, double t, DubinsPath* newpath);
  132. #endif // DUBINS_H