官方文档参阅:http://wiki.ros.org/pluginlib

有时候,可能会需要将替换ROS默认的planner替换成别的planner或我们自己的planner。这就涉及到了新planner包的建立和配置。

建立一个新的planner,大致分为以下几个步骤:

1. 实现nav_core包中的base_global_planner或base_local_planner接口,来建立一个新的planner包。

2. 在planner源码中添加:PLUGINLIB_EXPORT_CLASS宏,用于注册planner,否则ROS会不知道你的这个类是一个planner。

3. 在你的项目中添加your_planner_plugin.xml,用于声明你的planner。

4. 在package.xml中添加export。这里特别需要注意一点,如果你的export看起来像下面这样:

    <export>
<nav_core plugin="${prefix}/planner_plugin.xml" />
</export>

那么,一定要记得在package.xml中添加:

  <build_depend>nav_core</build_depend>
<exec_depend>nav_core</exec_depend>

否则,你会发现编译全对,但启动move_base就是找不到你的planner。会出来类似下面的错误:

Failed to create the your_planner/YourPlannerROS planner, are you sure it is properly registered and that the containing library is built?
Exception: According to the loaded plugin descriptions the class your_planner/YourPlannerROS with base class type nav_core::BaseGlobalPlanner does not exist.
Declared types are carrot_planner/CarrotPlanner global_planner/GlobalPlanner navfn/NavfnROS.

无论你怎么调试,系统就是找不到你的planner。

5. 最后一步是编写CMakefileLists.txt。一定要注意install你的lib文件和plugin.xml文件。不install的话有时会因找不到这些文件而失败:

install(TARGETS your_planner
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
) install(FILES your_planner_plugin.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

使用自己的planner进行测试时,推荐使用catkin_make_isolated --install进行编译,然后source install_isolated/setup.bash。使用devel_isolated/setup.bash有时会找不到planner。

PS:如果调试的时候发现还是出错,想查具体错误原因,可以修改move_base中下面这段:

    //initialize the global planner
try {
planner_ = bgp_loader_.createInstance(global_planner);
planner_->initialize(bgp_loader_.getName(global_planner), planner_costmap_ros_);
} catch (const pluginlib::PluginlibException& ex) {
ROS_FATAL("Failed to create the %s planner, are you sure it is properly registered and that the containing library is built? Exception: %s", global_planner.c_str(), ex.what());
exit();
}

将它修改为:

    //initialize the global planner
try {
planner_ = bgp_loader_.createInstance(global_planner);
planner_->initialize(bgp_loader_.getName(global_planner), planner_costmap_ros_);
}
catch (const pluginlib::LibraryLoadException& ex) {
ROS_FATAL("pluginlib::LibraryLoadException");
exit();
}
catch (const pluginlib::ClassLoaderException& ex) {
ROS_FATAL("pluginlib::ClassLoaderException");
exit();
}
catch (const pluginlib::LibraryUnloadException& ex) {
ROS_FATAL("pluginlib::LibraryUnloadException");
exit();
}
catch (const pluginlib::CreateClassException& ex) {
ROS_FATAL("pluginlib::CreateClassException");
exit();
}
catch (const pluginlib::PluginlibException& ex) {
ROS_FATAL("Failed to create the %s planner, are you sure it is properly registered and that the containing library is built? Exception: %s", global_planner.c_str(), ex.what());
exit();
}

就可以看到具体的错误原因了,local planner和global planner方法相似。

最新文章

  1. js中列表控件排序箭头,在wke中不支持的解决办法
  2. 【原创】.NET Core应用类型(Portable apps &amp; Self-contained apps)
  3. 系统级IO实践学习记录
  4. MVC4发布到IIS7报404错误
  5. C#学习笔记五: C#3.0Lambda表达式及Linq解析
  6. 一步步搭建自己的轻量级MVCphp框架-(一)什么是PHP框架以及MVC设计模式
  7. 跨平台网络通信与服务器框架 acl 3.2.0 发布
  8. TableView_编辑 实例代码
  9. HDU 5839 Special Tetrahedron
  10. Java基础学习-三元运算符和键盘录入的基本步骤和使用
  11. c# 采用datatable 快速导入数据至MSSQL的方法分享
  12. web列表总结
  13. LeetCode 12 - 整数转罗马数字 - [简单模拟]
  14. Asynchronous Programming
  15. B-Tree外存数据结构 _(B 树)第二部分
  16. 消息监听器无法注入bean
  17. 你知道Windows和WordPress上帝模式吗?
  18. 1月11日Atom 插件安装。
  19. jenkins坑—— shell 命令返回空导致构建失败
  20. 【leetcode 简单】 第六十六题 用栈实现队列

热门文章

  1. spark 源码分析之十一--Spark RPC剖析之TransportClient、TransportServer剖析
  2. 使用ASM实现动态代理
  3. Linux 下实践 VxLAN:虚拟机和 Docker 场景
  4. CDN绕过姿势小结
  5. angularjs通信以及postmessage与iframe通信
  6. 从windows10迁移到Linux Deepin
  7. 一次简单的SQL手工注入
  8. Netty学习(六)-LengthFieldBasedFrameDecoder解码器
  9. Flink Metrics 源码解析
  10. SQL获取客户端网卡电脑名称等信息