Size: 2726
Comment:
|
Size: 2795
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
## note = [[pluginlib/Tutorials/Writing and Using a Simple Plugin]] | ## note = This tutorial assumes that you have completed the previous tutorials:[[pluginlib/Tutorials/Writing and Using a Simple Plugin]] |
Note: This tutorial assumes that you have completed the previous tutorials:nodelet/Tutorials/Running a nodelet. |
![]() |
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 (may not be correct)
MyNodelet.h
#include <nodelet/nodelet.h> namespace nodelets { class MyNodlet : public nodelet::Nodelet { public: virtual void onInit(); }; }
MyNodelet.cpp
// this should really be in the implementation (.cpp file) #include <pluginlib/class_list_macros.h> PLUGINLIB_DECLARE_CLASS(nodelets, my_nodelet, nodelets::MyNodlet, nodelet::Nodelet) namespace nodelets { MyNodelet::onInit() { NODELET_DEBUG("Initializing nodelet..."); } }
nodelet_plugins.xml
<library path="lib/libmynodelet"> <class name="nodelets/my_nodelet" type="nodelets::MyNodlet" base_class_type="nodelet::Nodelet"> <description> This is an example nodelet </description> </class> </library>
manifest.xml
... <export> <nodelet plugin="${prefix}/nodlet_plugins.xml" /> </export> ...
mynodelet.launch
<launch> <node pkg="nodelet" type="nodelet" name="standalone_nodelet" args="manager" output="screen"/> <node pkg="nodelet" type="nodelet" name="MyNodelet" args="load nodelets/my_nodelet standalone_nodelet" output="screen"> </node> </launch>