参考 navigation_tutorials 的 nav2_straightline_planner
1. nav2_straightline_planner 继承自 nav2_core::GlobalPlanne, 需要重载的函数实现.
createPlan()方法需要开始位姿到目标位姿的实现. 返回一个 nav_msgs::msg::Path 给 planner server.
2. 导出插件
在插件源码最后添加
#include "pluginlib/class_list_macros.hpp" PLUGINLIB_EXPORT_CLASS(nav2_straightline_planner::StraightLine, nav2_core::GlobalPlanner)
说明我这个源码是个插件, 在运行的时候用了probe用.
然后建立插件的说明文件 global_planner_plugin.xml 给 ROS用.
3. 然后编译
CMakeLists.txt 相关
点击(此处)折叠或打开
- project(nav2_straightline_planner)
- find_package(builtin_interfaces REQUIRED)
- find_package(tf2_ros REQUIRED)
- find_package(nav2_costmap_2d REQUIRED)
- find_package(nav2_core REQUIRED)
- find_package(pluginlib REQUIRED)
- set(library_name ${PROJECT_NAME}_plugin)
- set(dependencies
- rclcpp
- rclcpp_action
- rclcpp_lifecycle
- std_msgs
- visualization_msgs
- nav2_util
- nav2_msgs
- nav_msgs
- geometry_msgs
- builtin_interfaces
- tf2_ros
- nav2_costmap_2d
- nav2_core
- pluginlib
- )
- add_library(${library_name} SHARED
- src/straight_line_planner.cpp
- )
- ament_target_dependencies(${library_name}
- ${dependencies}
- )
- target_compile_definitions(${library_name} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
- pluginlib_export_plugin_description_file(nav2_core global_planner_plugin.xml)
- install(TARGETS ${library_name}
- ARCHIVE DESTINATION lib
- LIBRARY DESTINATION lib
- RUNTIME DESTINATION lib/${PROJECT_NAME}
- )
- install(FILES global_planner_plugin.xml
- DESTINATION share/${PROJECT_NAME}
- )
- ament_export_include_directories(include)
- ament_export_libraries(${library_name})
- ament_export_dependencies(${dependencies})
- ament_package()
点击(此处)折叠或打开
- <export>
- <build_type>ament_cmake</build_type>
- <nav2_core plugin="${prefix}/global_planner_plugin.xml" />
- </export>
在costmap_params.xml中. foxy版本以及后续版本的写法. 注意参数是通过 . 传递给 插件源码的.
4. 测试一下吧.