在costmap_2d 中,大量使用了plugin技术实现可配置的layer和planner,为程序提供了很好的扩展性,而且这种扩展是不需要重新编译就能够实现。
首先来看costmap_2d中使用到的plugin:
bob@bob-Think:~$ rospack plugins --attrib=plugin costmap_2d
costmap_2d /opt/ros/indigo/share/costmap_2d/costmap_plugins.xml
bob@bob-Think:~$ cat /opt/ros/indigo/share/costmap_2d/costmap_plugins.xml
<class_libraries>
<library path="liblayers">
<class type="costmap_2d::InflationLayer" base_class_type="costmap_2d::Layer">
<description>Inflates obstacles to speed collision checking and to make robot prefer to stay away from obstacles.</description>
</class>
<class type="costmap_2d::ObstacleLayer" base_class_type="costmap_2d::Layer">
<description>Listens to laser scan and point cloud messages and marks and clears grid cells.</description>
</class>
<class type="costmap_2d::StaticLayer" base_class_type="costmap_2d::Layer">
<description>Listens to OccupancyGrid messages and copies them in, like from map_server.</description>
</class>
<class type="costmap_2d::VoxelLayer" base_class_type="costmap_2d::Layer">
<description>Similar to obstacle costmap, but uses 3D voxel grid to store data.</description>
</class>
</library>
</class_libraries>
这里注册了4个plugin,正如之前的关于这些类的分析。
然后再将这个plugin配置文件写入到package.xml:
bob@bob-Think:/opt/ros/indigo/share/costmap_2d$ cat package.xml
<package>
<name>costmap_2d</name>
<version>1.12.5</version>
<description>
This package provides an implementation of a 2D costmap that takes in sensor data from the world, builds a 2D or 3D occupancy grid of the data (depending on whether a voxel based implementation is used), and inflates costs in a 2D costmap based on the occupancy grid and a user specified inflation radius. This package also provides support for map_server based initialization of a costmap, rolling window based costmaps, and parameter based subscription to and configuration of sensor topics.
</description>
<author>Eitan Marder-Eppstein</author>
<author>David V. Lu!!</author>
<author>Dave Hershberger</author>
<author>contradict@gmail.com</author>
<maintainer email="davidvlu@gmail.com">David V. Lu!!</maintainer>
<maintainer email="mferguson@fetchrobotics.com">Michael Ferguson</maintainer>
<license>BSD</license>
<url>http://wiki.ros.org/costmap_2d</url>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>cmake_modules</build_depend>
<build_depend>dynamic_reconfigure</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>laser_geometry</build_depend>
<build_depend>map_msgs</build_depend>
<build_depend>message_filters</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>nav_msgs</build_depend>