1.为ä»ä¹ä¸äºå
¬å¸è¿å¨ç¨robotframework
2.Navigation包 Global_planner全局路径规划源码详细解析
为ä»ä¹ä¸äºå ¬å¸è¿å¨ç¨robotframework
å 为ç®åæä¸æã
ç¨pipå°robotframeworkåºå®è£ å°Pythonåºç®å½ä¸ã
å®è£ RobotFrameworkåï¼æºç 就已ç»å¨Pythonåºç®å½ä¸ï¼è¦åçå°±æ¯æ¾å°å®ãå¨Pythonç®å½ä¸ï¼æ¾å°site-packagesæ件夹ï¼site-packages\robotç®å½åæ¾çå°±æ¯RobotFrameworkçæºç ã
robotframeæ¯ä¸ä¸ªæµè¯æ¡æ¶å®çæµè¯åºæ¬é«äºåå æµè¯ï¼ä¹å°±æ¯è¯´ä¸éè¦ä½¿ç¨Junit类似çjavaè¯è¨å¯¹Javaååå æµè¯ï¼å°robotæµè¯çå±é¢å·²ç»æ¯å¨æµè¯ï¼æ们ç¼åçJAVA代ç é»è¾æ¯å¦æ£ç¡®ï¼ä¹å°±æ¯è¯´è¿ä¸ªæ¶åçjavaæ¯å ·ä½çå¯æ§è¡ç代ç ï¼ä½ è¿ä¸ªæ¶åéè¦çåªæ¯ç±robotç»å®è¾å ¥ï¼ä¹åæ ¡éªJavaçè¾åºè¿ä¸ªè¿ç¨èå·²ã
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,以防万一。然后检查起点和终点是文件读取源码否在我们所需要的坐标系下,一般在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-12-22 17:06
2024-12-22 16:38
2024-12-22 15:29
2024-12-22 15:14
2024-12-22 15:10
2024-12-22 14:37