path.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * space_server 任务路径管理。
  3. *
  4. * © 2020 成都河狸智能科技有限责任公司。保留所有权利。
  5. *
  6. * 作者: zhq1229
  7. */
  8. #ifndef __PATH_H__
  9. #define __PATH_H__
  10. #include <map>
  11. #include <vector>
  12. #include <string>
  13. #include <memory>
  14. #include "task/map.h"
  15. using PointId = unsigned int;
  16. using PathId = unsigned int;
  17. namespace task {
  18. namespace path {
  19. struct ChildPoint {
  20. ChildPoint():
  21. ptr(nullptr),
  22. g(0.0f) {}
  23. std::shared_ptr<struct PathPoint> ptr;
  24. float g;
  25. };
  26. struct AddPoint {
  27. AddPoint():
  28. forward(nullptr),
  29. reverse(nullptr),
  30. forward_ang(0.0f),
  31. reverse_ang(0.0f),
  32. max_vel(0.6f) {}
  33. std::shared_ptr<struct PathPoint> forward;
  34. std::shared_ptr<struct PathPoint> reverse;
  35. float forward_ang;
  36. float reverse_ang;
  37. float max_vel;
  38. };
  39. struct PathPoint {
  40. PathPoint():
  41. point_id(0),
  42. path_id(0),
  43. x(0.0f),
  44. y(0.0f),
  45. yaw(0.0f),
  46. type(""),
  47. father(nullptr),
  48. g(0.0f),
  49. h(0.0f),
  50. f(0.0f),
  51. closed(false) {
  52. children.clear();
  53. }
  54. PathPoint(
  55. PointId point_idt,
  56. PathId path_idt,
  57. float xt,
  58. float yt,
  59. float yawt,
  60. std::string typet = ""):
  61. point_id(point_idt),
  62. path_id(path_idt),
  63. x(xt),
  64. y(yt),
  65. yaw(yawt),
  66. type(typet),
  67. father(nullptr),
  68. g(0.0f),
  69. h(0.0f),
  70. f(0.0f),
  71. closed(false) {}
  72. void add_child(
  73. std::shared_ptr<struct PathPoint> ptr, float g) {
  74. struct ChildPoint c;
  75. c.ptr = ptr;
  76. c.g = g;
  77. children.push_back(c);
  78. }
  79. void set_plan(
  80. std::shared_ptr<struct PathPoint> fa, float _g, float _h) {
  81. father = fa;
  82. g = _g;
  83. h = _h;
  84. f = g + h;
  85. }
  86. void close() {
  87. closed = true;
  88. }
  89. void setAP(
  90. std::shared_ptr<struct PathPoint> f,
  91. std::shared_ptr<struct PathPoint> r,
  92. float forward_ang, float reverse_ang,
  93. float max_vel) {
  94. ap.forward = f;
  95. ap.reverse = r;
  96. ap.forward_ang = forward_ang;
  97. ap.reverse_ang = reverse_ang;
  98. ap.max_vel = max_vel;
  99. }
  100. PointId point_id;
  101. PathId path_id;
  102. float x;
  103. float y;
  104. float yaw;
  105. std::string type;
  106. std::vector<struct ChildPoint> children;
  107. AddPoint ap;
  108. std::shared_ptr<struct PathPoint> father;
  109. float g, h, f;
  110. bool closed;
  111. };
  112. struct PointInfo
  113. {
  114. PointId point_id;
  115. std::string type;
  116. std::string name;
  117. float x;
  118. float y;
  119. float yaw;
  120. };
  121. struct PathInfo {
  122. PathInfo():
  123. path_id(0),
  124. name(""),
  125. type(""),
  126. dir("forbid"),
  127. max_vel(0.6f),
  128. forward_ang(0.0f),
  129. reverse_ang(0.0f) {}
  130. PathId path_id;
  131. MapId map_id;
  132. std::string name;
  133. std::string type;
  134. std::string dir;
  135. float max_vel;
  136. float forward_ang;
  137. float reverse_ang;
  138. std::vector<PointInfo> points;
  139. };
  140. using PathPointPtr = std::shared_ptr<struct PathPoint>;
  141. using Path = std::vector<PathPointPtr>;
  142. using Paths = std::vector<PathPointPtr>;
  143. using MapPaths = std::map<MapId, Paths>;
  144. using PathInfos = std::map<PathId, PathInfo>;
  145. using MapPathInfos = std::map<MapId, PathInfos>;
  146. Paths paths(MapId map_id);
  147. bool paths(MapId map_id, Paths &paths);
  148. PathInfos pathInfos(MapId map_id);
  149. PathPointPtr pathPointPtr(Paths &paths, PointId point_id);
  150. PathPointPtr onPathPointPtr(Paths &paths, float x, float y, float error);
  151. int init();
  152. int shutdown();
  153. } // namespace path
  154. } // namespace task
  155. #endif // __PATH_H__