1.Navigation包 Global_planner全局路径规划源码详细解析
Navigation包 Global_planner全局路径规划源码详细解析
学习总结,如有错误欢迎指正!全局全局一丶plan_node.cpp从程序入口开始,源码源码首先在plan_node.cpp的安卓安卓main函数中,初始化了全局路径规划器。全局全局仿站酷源码
costmap_2d::Costmap2DROS?源码源码防封号电销系统源码lcr("costmap",?buffer);global_planner::PlannerWithCostmap?pppp("planner",?&lcr);在函数PlannerWithCostmap中设置了两种调用makePlan的路径:
PlannerWithCostmap::PlannerWithCostmap(string?name,?Costmap2DROS*?cmap)?:GlobalPlanner(name,?cmap->getCostmap(),?cmap->getGlobalFrameID())?{ ros::NodeHandle?private_nh("~");cmap_?=?cmap;make_plan_service_?=?private_nh.advertiseService("make_plan",?&PlannerWithCostmap::makePlanService,?this);pose_sub_?=?private_nh.subscribe<rm::PoseStamped>("goal",?1,?&PlannerWithCostmap::poseCallback,?this);}1.通过make_plan服务
req.start.header.frame_id?=?"map";req.goal.header.frame_id?=?"map";bool?success?=?makePlan(req.start,?req.goal,?path);2.通过goal回调函数
//得到当前机器人在MAP中的位置cmap_->getRobotPose(global_pose);makePlan(global_pose,?*goal,?path);在getRobotPose函数中,通过tf_.transform(robot_pose,安卓安卓 global_pose, global_frame_);函数,默认将机器人pose从base_link转换到map坐标系下,全局全局可通过参数设置。源码源码得到起始点和目标点传入到makePlan中。安卓安卓
二丶 planner_core.cpp//register?全局全局this?planner?as?a?BaseGlobalPlanner?pluginPLUGINLIB_EXPORT_CLASS(global_planner::GlobalPlanner,?nav_core::BaseGlobalPlanner)global_planner 是基类nav_core :: BaseGlobalPlanner的一个插件子类
首先在构造函数中需要初始化GlobalPlanner,在initialize中对一些参数进行赋值。源码源码
GlobalPlanner::GlobalPlanner(std::string?安卓安卓国旗头像生成器源码name,?costmap_2d::Costmap2D*?costmap,?std::string?frame_id)?:GlobalPlanner()?{ //initialize?the?plannerinitialize(name,?costmap,?frame_id);}当调用makePlan时,首先就是全局全局判断是否已经被初始化:
//?code?line?~makePlan()if?(!initialized_)?{ ROS_ERROR("This?planner?has?not?been?initialized?yet,?but?it?is?being?used,?please?call?initialize()?before?use");return?false;}m初始化完成之后,清除之前规划的源码源码Plan,以防万一。然后检查起点和终点是神奇9转主图源码否在我们所需要的坐标系下,一般在map系下。
//clear?the?plan,?just?in?case?,?code?line?makePlan()plan.clear();if?(goal.header.frame_id?!=?global_frame)?{ ...}if?(start.header.frame_id?!=?global_frame){ ...}将世界坐标系的点(map 坐标系)转换成图像坐标系(图像左下角)下的点(以像素表示)
if?(!costmap_->worldToMap(wx,?wy,?goal_x_i,?goal_y_i))?{ ?ROS_WARN_THROTTLE(1.0,"The?goal?sent?to?the?global?planner?is?off?the?global?costmap.?Planning?will?always?fail?to?this?goal.");?return?false;}在Costmap2D和GlobalPlanner中都有实现worldToMap,其实都是北京源码资本是骗子吗一样的,在GlobalPlanner中则需要通过调用Costmap2D来获取局部地图的起始点和分辨率,而在Costmap2D则可以直接使用全局变量。
bool?Costmap2D::worldToMap(double?wx,?double?wy,?unsigned?int&?mx,?unsigned?int&?my)?const{ if?(wx?<?origin_x_?||?wy?<?origin_y_)return?false;mx?=?(int)((wx?-?origin_x_)?/?resolution_);my?=?(int)((wy?-?origin_y_)?/?resolution_);if?(mx?<?size_x_?&&?my?<?size_y_)return?true;return?false;}old_navfnbehavior ?作为一种旧式规划行为:
The start of the path does not match the actual start location.
The very end of the path moves along grid lines.
All of the coordinates are slightly shifted by half a grid cell
现在在worldToMap所使用的convert_offset_ = 0
接下来将机器人Robot所在的位置,在costmap中设置成free,当前位置不可能是一个障碍物。 即在clearRobotCell()函数中:mx,my即当前机器人位置。
PlannerWithCostmap::PlannerWithCostmap(string?name,?Costmap2DROS*?cmap)?:GlobalPlanner(name,?cmap->getCostmap(),?cmap->getGlobalFrameID())?{ ros::NodeHandle?private_nh("~");cmap_?=?cmap;make_plan_service_?=?private_nh.advertiseService("make_plan",?&PlannerWithCostmap::makePlanService,?this);pose_sub_?=?private_nh.subscribe<rm::PoseStamped>("goal",?1,?&PlannerWithCostmap::poseCallback,?this);}0设置规划地图边框:outlineMap,此函数由参数outline_map_决定。 根据costmap跟起始终止点计算网格的potential,计算的算法有两种:Dijkstra和A*,具体算法便不再讨论,资料很多。 当提取到plan之后,调用getPlanFromPotential,把path转换变成geometry_msgs::PoseStamped数据类型。
PlannerWithCostmap::PlannerWithCostmap(string?name,?Costmap2DROS*?cmap)?:GlobalPlanner(name,?cmap->getCostmap(),?cmap->getGlobalFrameID())?{ ros::NodeHandle?private_nh("~");cmap_?=?cmap;make_plan_service_?=?private_nh.advertiseService("make_plan",?&PlannerWithCostmap::makePlanService,?this);pose_sub_?=?private_nh.subscribe<rm::PoseStamped>("goal",?1,?&PlannerWithCostmap::poseCallback,?this);}1此时便得到所需要的路径plan,最终调用OrientationFilter平滑之后发布出去。
PlannerWithCostmap::PlannerWithCostmap(string?name,?Costmap2DROS*?cmap)?:GlobalPlanner(name,?cmap->getCostmap(),?cmap->getGlobalFrameID())?{ ros::NodeHandle?private_nh("~");cmap_?=?cmap;make_plan_service_?=?private_nh.advertiseService("make_plan",?&PlannerWithCostmap::makePlanService,?this);pose_sub_?=?private_nh.subscribe<rm::PoseStamped>("goal",?1,?&PlannerWithCostmap::poseCallback,?this);}22024-11-23 12:49
2024-11-23 12:46
2024-11-23 12:45
2024-11-23 12:44
2024-11-23 12:05
2024-11-23 11:37
2024-11-23 10:44
2024-11-23 10:30