赞
踩
1.编写路径规划器类
1.1创建工作空间,创建功能包(nav_core、roscpp、rospy、std_msgs)
1.2在src和include中编写相关代码
在CMakeLists.txt中修改:
catkin_package( INCLUDE_DIRS include # LIBRARIES better_astar_global_planner CATKIN_DEPENDS nav_core roscpp rospy std_msgs # DEPENDS system_lib ) include_directories( include/${PROJECT_NAME} ${catkin_INCLUDE_DIRS} ) add_library(learn_global_planner_lib src/better_astar.cpp )
编译后在/devel/lib中生成liblearn_global_planner_lib.so文件,后续要用。
2.编写插件
2.1插件注册
在.cpp文件的头文件后加入(注:LearnAstar_planner::LearnAstarPlannerROS为自己编写的代码,类似于 nav_core::BaseGlobalPlanner)
PLUGINLIB_EXPORT_CLASS(LearnAstar_planner::LearnAstarPlannerROS, nav_core::BaseGlobalPlanner)
2.2创建.xml文件(注意:liblearn_global_planner_lib没有.so)
<library path="lib/liblearn_global_planner_lib">
<class name="LearnAstar_planner/LearnAstarPlannerROS" type="LearnAstar_planner::LearnAstarPlannerROS" base_class_type="nav_core::BaseGlobalPlanner">
<description>This is the better A* global planner plugin </description>
</class>
</library>
2.3向ros包提供插件
在package.xml中加入
<export>
<!-- Other tools can request additional information be placed here -->
<nav_core plugin="${prefix}/learn_global_planner_plugin.xml" />
</export>
然后catkin_make,到此,全局路径规划器编写完成。
3.测试编写的全局路径规划器
3.1任一的仿真环境中,在move_base.launch文件中添加
<param name="base_global_planner" value="LearnAstar_planner/LearnAstarPlannerROS"/>
3.2逐一启动仿真环境文件和导航文件。
参考:
1.http://wiki.ros.org/navigation/Tutorials/Writing%20A%20Global%20Path%20Planner%20As%20Plugin%20in%20ROS/
2.https://www.bilibili.com/video/BV1U44y137dc/?spm_id_from=333.788&vd_source=e94514567e600eb634e59dea01faea91
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。