| Note: This tutorial assumes that you have completed the previous tutorials:pluginlib/Tutorials/Writing and Using a Simple Plugin. |
Porting nodes to nodelets
Description:Tutorial Level: BEGINNER
Contents
Work in progress...(see nodelet_tutorial_math for an example)
- add the necessary #includes
- get rid of int main()
- subclass nodelet::Nodelet
- move code from constructor to onInit()
- add the PLUGINLIB_DECLARE_CLASS macro
add the <nodelet> item in the <export> part of the package manifest
- create the .xml file to define the nodelet as a plugin
- make the necessary changes to CMakeLists.txt (comment out a rosbuild_add_executable, add a rosbuild_add_library)
Minimal Nodelet
MyNodeletClass.h
#include <nodelet/nodelet.h>
namespace example_pkg
{
class MyNodeletClass : public nodelet::Nodelet
{
public:
virtual void onInit();
};
}MyNodeletClass.cpp
// this should really be in the implementation (.cpp file)
#include <pluginlib/class_list_macros.h>
// watch the capitalization carefully
PLUGINLIB_DECLARE_CLASS(example_pkg, MyNodeletClass, example_pkg::MyNodeletClass, nodelet::Nodelet)
namespace example_pkg
{
void MyNodeletClass::onInit()
{
NODELET_DEBUG("Initializing nodelet...");
}
}nodelet_plugins.xml
<library path="lib/libMyNodeletClass"> <class name="example_pkg/MyNodeletClass" type="example_pkg::MyNodeletClass" base_class_type="nodelet::Nodelet"> <description> This is my nodelet. </description> </class> </library>
manifest.xml
...
<export>
<nodelet plugin="${prefix}/nodelet_plugins.xml" />
</export>
...mynodelet.launch
<launch> <node pkg="nodelet" type="nodelet" name="standalone_nodelet" args="manager" output="screen"/> <node pkg="nodelet" type="nodelet" name="MyNodeletClass" args="load example_pkg/MyNodeletClass standalone_nodelet" output="screen"> </node> </launch>






