当前位置:   article > 正文

hybridAStar_dubinsshot

dubinsshot
  1. Node3D* Algorithm::hybridAStar(Node3D& start,
  2. const Node3D& goal,
  3. Node3D* nodes3D,
  4. Node2D* nodes2D,
  5. int width,
  6. int height,
  7. CollisionDetection& configurationSpace,
  8. float* dubinsLookup,
  9. Visualize& visualization) {
  10. // PREDECESSOR AND SUCCESSOR INDEX
  11. int iPred/*前任*/, iSucc/*继任*/;
  12. //*g:表示起点到当前节点的cost的累加(通常是dijkstar的代价)
  13. float newG;
  14. // Number of possible directions, 3 for forward driving and an additional 3 for reversing
  15. int dir = Constants::reverse ? 6 : 3;
  16. // Number of iterations the algorithm has run for stopping based on Constants::iterations
  17. int iterations = 0;
  18. // VISUALIZATION DELAY
  19. ros::Duration d(0.003);
  20. // OPEN LIST AS BOOST IMPLEMENTATION
  21. typedef boost::heap::binomial_heap<Node3D*,
  22. boost::heap::compare<CompareNodes>
  23. > priorityQueue;
  24. priorityQueue O;
  25. //*h:表示当前节点到目标点估计出来的代价(通过启发函数)
  26. // update h value
  27. updateH(start, goal, nodes2D, dubinsLookup, width, height, configurationSpace, visualization);
  28. // mark start as open
  29. start.open();
  30. // push on priority queue aka open list
  31. O.push(&start);
  32. iPred = start.setIdx(width, height);
  33. nodes3D[iPred] = start;
  34. // NODE POINTER
  35. Node3D* nPred;
  36. Node3D* nSucc;
  37. // float max = 0.f;
  38. // continue until O empty
  39. while (!O.empty()) {
  40. // // DEBUG
  41. // Node3D* pre = nullptr;
  42. // Node3D* succ = nullptr;
  43. // std::cout << "\t--->>>" << std::endl;
  44. // for (priorityQueue::ordered_iterator it = O.ordered_begin(); it != O.ordered_end(); ++it) {
  45. // succ = (*it);
  46. // std::cout << "VAL"
  47. // << " | C:" << succ->getC()
  48. // << " | x:" << succ->getX()
  49. // << " | y:" << succ->getY()
  50. // << " | t:" << helper::toDeg(succ->getT())
  51. // << " | i:" << succ->getIdx()
  52. // << " | O:" << succ->isOpen()
  53. // << " | pred:" << succ->getPred()
  54. // << std::endl;
  55. // if (pre != nullptr) {
  56. // if (pre->getC() > succ->getC()) {
  57. // std::cout << "PRE"
  58. // << " | C:" << pre->getC()
  59. // << " | x:" << pre->getX()
  60. // << " | y:" << pre->getY()
  61. // << " | t:" << helper::toDeg(pre->getT())
  62. // << " | i:" << pre->getIdx()
  63. // << " | O:" << pre->isOpen()
  64. // << " | pred:" << pre->getPred()
  65. // << std::endl;
  66. // std::cout << "SCC"
  67. // << " | C:" << succ->getC()
  68. // << " | x:" << succ->getX()
  69. // << " | y:" << succ->getY()
  70. // << " | t:" << helper::toDeg(succ->getT())
  71. // << " | i:" << succ->getIdx()
  72. // << " | O:" << succ->isOpen()
  73. // << " | pred:" << succ->getPred()
  74. // << std::endl;
  75. // if (pre->getC() - succ->getC() > max) {
  76. // max = pre->getC() - succ->getC();
  77. // }
  78. // }
  79. // }
  80. // pre = succ;
  81. // }
  82. // pop node with lowest cost from priority queue
  83. nPred = O.top();
  84. // set index
  85. iPred = nPred->setIdx(width, height);
  86. iterations++;
  87. // RViz visualization
  88. if (Constants::visualization) {
  89. visualization.publishNode3DPoses(*nPred);
  90. visualization.publishNode3DPose(*nPred);
  91. d.sleep();
  92. }
  93. // _____________________________
  94. // LAZY DELETION of rewired node
  95. // if there exists a pointer this node has already been expanded
  96. if (nodes3D[iPred].isClosed()) {
  97. // pop node from the open list and start with a fresh node
  98. O.pop();
  99. continue;
  100. }
  101. // _________________
  102. // EXPANSION OF NODE
  103. else if (nodes3D[iPred].isOpen()) {
  104. // add node to closed list
  105. nodes3D[iPred].close();
  106. // remove node from open list
  107. O.pop();
  108. // _________
  109. // GOAL TEST//到达目标结束运算
  110. if (*nPred == goal || iterations > Constants::iterations) {
  111. // DEBUG
  112. return nPred;
  113. }
  114. // ____________________
  115. // CONTINUE WITH SEARCH
  116. else {
  117. // _______________________
  118. // SEARCH WITH DUBINS SHOT//杜宾斯到点结束运算
  119. if (Constants::dubinsShot && nPred->isInRange(goal) && nPred->getPrim() < 3) {
  120. nSucc = dubinsShot(*nPred, goal, configurationSpace);
  121. if (nSucc != nullptr && *nSucc == goal) {
  122. //DEBUG
  123. // std::cout << "max diff " << max << std::endl;
  124. return nSucc;
  125. }
  126. }
  127. // ______________________________
  128. // SEARCH WITH FORWARD SIMULATION
  129. //从不同的方向搜索
  130. for (int i = 0; i < dir; i++) {
  131. // create possible successor
  132. nSucc = nPred->createSuccessor(i);
  133. // set index of the successor
  134. //创建可能的继任者
  135. iSucc = nSucc->setIdx(width, height);
  136. // ensure successor is on grid and traversable
  137. //确保继任者在网格上且可遍历
  138. if (nSucc->isOnGrid(width, height) && configurationSpace.isTraversable(nSucc)) {
  139. // ensure successor is not on closed list or it has the same index as the predecessor
  140. //确保继任者不在关闭列表中,或其索引与前任相同
  141. if (!nodes3D[iSucc].isClosed() || iPred == iSucc) {
  142. // calculate new G value
  143. //计算起点到当前节点的cost的累加
  144. nSucc->updateG();
  145. newG = nSucc->getG();
  146. // if successor not on open list or found a shorter way to the cell
  147. //如果继任者不在打开列表中或找到了通向单元格的较短路径
  148. if (!nodes3D[iSucc].isOpen() || newG < nodes3D[iSucc].getG() || iPred == iSucc) {
  149. // calculate H value
  150. //计算当前节点到目标点估计出来的代价
  151. updateH(*nSucc, goal, nodes2D, dubinsLookup, width, height, configurationSpace, visualization);
  152. // if the successor is in the same cell but the C value is larger
  153. //如果后继单元格位于同一单元格中,但C值较大
  154. if (iPred == iSucc && nSucc->getC() > nPred->getC() + Constants::tieBreaker) {
  155. delete nSucc;
  156. continue;
  157. }
  158. // if successor is in the same cell and the C value is lower, set predecessor to predecessor of predecessor
  159. //如果后继项位于同一单元格中,并且C值较低,请将前置项设置为前置项的前置项
  160. else if (iPred == iSucc && nSucc->getC() <= nPred->getC() + Constants::tieBreaker) {
  161. nSucc->setPred(nPred->getPred());
  162. }
  163. if (nSucc->getPred() == nSucc) {
  164. std::cout << "looping";
  165. }
  166. // put successor on open list
  167. nSucc->open();
  168. nodes3D[iSucc] = *nSucc;
  169. O.push(&nodes3D[iSucc]);
  170. delete nSucc;
  171. } else { delete nSucc; }
  172. } else { delete nSucc; }
  173. } else { delete nSucc; }
  174. }
  175. }
  176. }
  177. }
  178. if (O.empty()) {
  179. return nullptr;
  180. }
  181. return nullptr;
  182. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/613639
推荐阅读
相关标签
  

闽ICP备14008679号