ROS中Plugin插件学习

ROS 的Plugin官方文档是以polygon为例。本文以global_planner和 carrot_planner为例。
在Navgation 中。global_planner 是基类nav_core :: BaseGlobalPlanner的一个插件子类。同时也提供了另外一个carrot_planner子类。以carrot_planner子类为例。

1 创建插件导入导出类

首先在自己创建的功能包中的导出类的cpp文件的起始位置加入:(global_planner中就是planner_core.cpp文件)

PLUGINLIB_EXPORT_CLASS(carrot_planner::CarrotPlanner, nav_core::BaseGlobalPlanner)

其中carrot::CarrotPlanne表示的是插件的名称,而后的nav_core::BaseGlobalPlanner是这个插件所依赖的基类。因此nav_core这个包即使在global_planner这个包出来之后也并为被作者删除。虽然其仅仅含有几个头文件。

2 添加plugin.xml插件描述文件

而后在carrot_planner包中加入 **plugin.xml文件. (插件描述文件)。 在carrot_planner包中为 bgp_plugin.xml。其内容如下:

<library path="lib/libcarrot_planner">
  <class name="carrot_planner/CarrotPlanner" type="carrot_planner::CarrotPlanner" base_class_type="nav_core::BaseGlobalPlanner">
    <description>
      A simple planner that seeks to place a legal carrot in-front of the robot
    </description>
  </class>
</library>

其中我们主要需要修改的是path 和class中的 name ,type, base_class_type.
其中 path 表示该库插件的存放位置。使用的是相对路径。在本例中即为:~/nkai_ws/devel/lib 。name即该插件的名称。 type为插件的类。本例即为 carrot_planner 的namespace中的 CarrotPlanner。 base_class_type。是其中的基类。在导航包中,如果要用自己的全局规划器,base_class_type均为 nav_core :: BaseGlobalPlanner.
<description>是对该插件功能的一个描述。
如果带有多个插件或者是插件在多个namespace下。可以参照 ROS官网plugin相关介绍 Plugin Description file

3 修改package.xml文件

修改package.xml文件,在最后加上如下

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

bgp_plugin.xml为之前描述文件的名称。{prefix}会自动寻找其路径。
同时为了使上述导出命令正常工作,提供的程序包必须直接依赖于包含插件接口的程序包,对于全局规划器,该程序包为nav_core。因此,carrot_planner软件包的package.xml中必须包含以下行:

<build_depend>nav_core</build_depend>
<run_depend>nav_core</run_depend>

在完成后对功能包进行编译。然后可以利用

rospack plugins --attrib=plugin nav_core

查看是否含有插件。

4 修改move_base使用插件

在move_base.launch 文件中加入以下代码

<param name="base_global_planner" value="carrotplanner/CarrotPlanner" /> 	

参考
global_planner解析
ROS 中 Plugin机制 (wiki)
ROS 中 写全局规划器插件介绍

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值