当前位置:   article > 正文

路径规划算法 快速搜索随机树(Rapid-exploration Random Tree)_快速探索随机树(rrt)是最快,最有效的无障碍路径寻找算法之一。 但是,它无法保证找

快速探索随机树(rrt)是最快,最有效的无障碍路径寻找算法之一。 但是,它无法保证找
机器人路径规划算法keyword

A* 已讲解了

然后是rrt 快速搜索随机树(Rapid-exploration Random Tree)
中文论文


然后有一份在ros上写的代码,这个是拷贝点击打开链接这个博客的代码

这份rrt代码也很简单,容易理解,代码变量名很清楚,顺便还学了ros的节点和rviz之类的写法,还是很不错的

这里这贴一个主节点代码,就是画边框和障碍物的,可以参考一下写法

  1. #include <ros/ros.h>
  2. #include <visualization_msgs/Marker.h>
  3. #include <path_planning/rrt.h>
  4. #include <path_planning/obstacles.h>
  5. #include <geometry_msgs/Point.h>
  6. #include <iostream>
  7. #include <cmath>
  8. #include <math.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <vector>
  12. using namespace rrt;
  13. void initializeMarkers(visualization_msgs::Marker &boundary,
  14. visualization_msgs::Marker &obstacle)
  15. {
  16. //init headers
  17. boundary.header.frame_id = obstacle.header.frame_id = "path_planner";
  18. boundary.header.stamp = obstacle.header.stamp = ros::Time::now();
  19. boundary.ns = obstacle.ns = "path_planner";
  20. boundary.action = obstacle.action = visualization_msgs::Marker::ADD;
  21. boundary.pose.orientation.w = obstacle.pose.orientation.w = 1.0;
  22. //setting id for each marker
  23. boundary.id = 110;
  24. obstacle.id = 111;
  25. //defining types
  26. boundary.type = visualization_msgs::Marker::LINE_STRIP;
  27. obstacle.type = visualization_msgs::Marker::LINE_LIST;
  28. //setting scale
  29. boundary.scale.x = 1;
  30. obstacle.scale.x = 0.2;
  31. //assigning colors
  32. boundary.color.r = obstacle.color.r = 0.0f;
  33. boundary.color.g = obstacle.color.g = 0.0f;
  34. boundary.color.b = obstacle.color.b = 0.0f;
  35. boundary.color.a = obstacle.color.a = 1.0f;
  36. }
  37. vector<geometry_msgs::Point> initializeBoundary()
  38. {
  39. vector<geometry_msgs::Point> bondArray;
  40. geometry_msgs::Point point;
  41. //first point
  42. point.x = 0;
  43. point.y = 0;
  44. point.z = 0;
  45. bondArray.push_back(point);
  46. //second point
  47. point.x = 0;
  48. point.y = 100;
  49. point.z = 0;
  50. bondArray.push_back(point);
  51. //third point
  52. point.x = 100;
  53. point.y = 100;
  54. point.z = 0;
  55. bondArray.push_back(point);
  56. //fourth point
  57. point.x = 100;
  58. point.y = 0;
  59. point.z = 0;
  60. bondArray.push_back(point);
  61. //first point again to complete the box
  62. point.x = 0;
  63. point.y = 0;
  64. point.z = 0;
  65. bondArray.push_back(point);
  66. return bondArray;
  67. }
  68. vector<geometry_msgs::Point> initializeObstacles()
  69. {
  70. vector< vector<geometry_msgs::Point> > obstArray;
  71. vector<geometry_msgs::Point> obstaclesMarker;
  72. obstacles obst;
  73. obstArray = obst.getObstacleArray();
  74. for(int i=0; i<obstArray.size(); i++)
  75. {
  76. for(int j=1; j<5; j++)
  77. {
  78. obstaclesMarker.push_back(obstArray[i][j-1]);
  79. obstaclesMarker.push_back(obstArray[i][j]);
  80. }
  81. }
  82. return obstaclesMarker;
  83. }
  84. int main(int argc,char** argv)
  85. {
  86. //initializing ROS
  87. ros::init(argc,argv,"env_node");
  88. ros::NodeHandle n;
  89. //defining Publisher
  90. ros::Publisher env_publisher = n.advertise<visualization_msgs::Marker>("path_planner_rrt",1);
  91. //defining markers
  92. visualization_msgs::Marker boundary;
  93. visualization_msgs::Marker obstacle;
  94. initializeMarkers(boundary, obstacle);
  95. //initializing rrtTree
  96. RRT myRRT(2.0,2.0);
  97. int goalX, goalY;
  98. goalX = goalY = 95;
  99. boundary.points = initializeBoundary();
  100. obstacle.points = initializeObstacles();
  101. env_publisher.publish(boundary);
  102. env_publisher.publish(obstacle);
  103. while(ros::ok())
  104. {
  105. env_publisher.publish(boundary);
  106. env_publisher.publish(obstacle);
  107. ros::spinOnce();
  108. ros::Duration(1).sleep();
  109. }
  110. return 1;
  111. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/547637
推荐阅读
相关标签
  

闽ICP备14008679号