@小鱼
custom_planner_plugin.xml代码:

<library path="nav2_custom_planner_plugin"> <class name="nav2_custom_planner/CustomPlanner" type="nav2_custom_planner::CustomPlanner" base_class_type="nav2_core::GlobalPlanner"> <description>是一个自定义示例插件,用于生成自定义路径。</description> </class> </library>

cmakelists.txt代码:“

cmake_minimum_required(VERSION 3.8) project(nav2_custom_planner) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(nav2_core REQUIRED) find_package(pluginlib REQUIRED) #包含头文件目录 include_directories(include) #定义库名称 set(library_name ${PROJECT_NAME}_Plugin) #创建共享库 add_library(${library_name} SHARED src/nav2_custom_planner.cpp) #指定库的依赖关系 ament_target_dependencies(${library_name} nav2_core pluginlib) #安装库文件到指定目录 install(TARGETS ${library_name} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION lib/${PROJECT_NAME} ) #安装头文件到指定目录 install(DIRECTORY include/ DESTINATION include/ ) #导出插件描述文件 pluginlib_export_plugin_description_file(nav2_core custom_planner_plugin.xml) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() ament_package()

package.xml代码:

<?xml version="1.0"?> <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> <package format="3"> <name>nav2_custom_planner</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="tingbo01@qq.com">tingbo</maintainer> <license>Apache-2.0</license> <buildtool_depend>ament_cmake</buildtool_depend> <depend>nav2_core</depend> <depend>pluginlib</depend> <test_depend>ament_lint_auto</test_depend> <test_depend>ament_lint_common</test_depend> <export> <build_type>ament_cmake</build_type> <nav2_core plugin="${prefix}/custom_planner_plugin.xml" /> </export> </package>