当前位置:   article > 正文

移动机器人gazebo仿真(5)—规划算法A*_ros gazebo global-planning

ros gazebo global-planning

参考博客:

MoveBace.cpp阅读笔记

贪心算法的一个典型案例——Dijkstra算法:     浅谈路径规划算法之Dijkstra算法

A*:      A*寻路算法   

关于寻路算法的一些思考(1)——A*算法介绍

ROS的全局规划代码介绍(A*)


重要:ROS Navigation的global_planner类继承关系与实现算法


导航实际流程为:

进行全局路径规划,在进行局部路径规划,然后发布速度

全局路径规划在makePlan函数中,该函数中调用了 planner_makePlanempty接口。
planner_为继承于BaseGlobalPlanner的实例,由pluginlib通过具体类的名字进行装载。
之后,调用tc_的setPlan接口,对局部路径规划器进行全局路径设置,然后,调用tc_的isReached接口进行判断,然后调用tc_的computeVelocityCommands接口,进行速度计算,然后进行速度下发。

tc_为继承于BaseLocalPlanner的实例,也是由pluginlinb通过具体类的名字进行装载。

下面带来两个问题,planner_怎么进行路径规划,以及tc_如何计算速度。
planner_在初始化时候,被塞入了planner_costmap_ros_
tc_在初始化时,被塞入了controller_costmap_ros_



在global planner的包中,注册了插件:global planner::GlobalPlanner

代码阅读:

global_planne

1、plan_node.cpp  

plan_node.cpp是全局规划代码的入口(代码注释都是自己理解然后添加,也许会有错误)

  1. #include <global_planner/planner_core.h>
  2. #include <navfn/MakeNavPlan.h>
  3. #include <boost/shared_ptr.hpp>
  4. #include <costmap_2d/costmap_2d_ros.h>
  5. namespace cm = costmap_2d;
  6. namespace rm = geometry_msgs;
  7. using std::vector;
  8. using rm::PoseStamped;
  9. using std::string;
  10. using cm::Costmap2D;
  11. using cm::Costmap2DROS;
  12. namespace global_planner {
  13. class PlannerWithCostmap : public GlobalPlanner {
  14. public:
  15. PlannerWithCostmap(string name, Costmap2DROS* cmap);
  16. bool makePlanService(navfn::MakeNavPlan::Request& req, navfn::MakeNavPlan::Response& resp);
  17. private:
  18. void poseCallback(const rm::PoseStamped::ConstPtr& goal);
  19. Costmap2DROS* cmap_;
  20. ros::ServiceServer make_plan_service_;
  21. ros::Subscriber pose_sub_;
  22. };
  23. //Publish a path for visualization purposes
  24. bool PlannerWithCostmap::makePlanService(navfn::MakeNavPlan::Request& req, navfn::MakeNavPlan::Response& resp) {
  25. vector<PoseStamped> path;
  26. req.start.header.frame_id = "/map";
  27. req.goal.header.frame_id = "/map";
  28. bool success = makePlan(req.start, req.goal, path);
  29. resp.plan_found = success;
  30. if (success) {
  31. resp.path = path;
  32. }
  33. return true;
  34. }
  35. void PlannerWithCostmap::poseCallback(const rm::PoseStamped::ConstPtr& goal) {
  36. tf::Stamped<tf::Pose> global_pose;
  37. cmap_->getRobotPose(global_pose);//获取机器人起始位姿
  38. vector<PoseStamped> path;
  39. rm::PoseStamped start;
  40. start.header.stamp = global_pose.stamp_;
  41. start.header.frame_id = global_pose.frame_id_;
  42. start.pose.position.x = global_pose.getOrigin().x();
  43. start.pose.position.y = global_pose.getOrigin().y();
  44. start.pose.position.z = global_pose.getOrigin().z();
  45. start.pose.orientation.x = global_pose.getRotation().x();
  46. start.pose.orientation.y = global_pose.getRotation().y();
  47. start.pose.orientation.z = global_pose.getRotation().z();
  48. start.pose.orientation.w = global_pose.getRotation().w();
  49. makePlan(start, *goal, path);//路径规划
  50. }
  51. PlannerWithCostmap::PlannerWithCostmap(string name, Costmap2DROS* cmap) :
  52. GlobalPlanner(name, cmap->getCostmap(), cmap->getGlobalFrameID()) {
  53. ros::NodeHandle private_nh("~");
  54. cmap_ = cmap;
  55. make_plan_service_ = private_nh.advertiseService("make_plan", &PlannerWithCostmap::makePlanService, this);
  56. pose_sub_ = private_nh.subsc
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/511724
推荐阅读
相关标签
  

闽ICP备14008679号