• Diff for "nodelet/Tutorials/Porting nodes to nodelets"
Differences between revisions 8 and 9
Revision 8 as of 2011-01-11 02:25:53
Size: 2726
Editor: TullyFoote
Comment:
Revision 9 as of 2011-01-11 02:26:30
Size: 2795
Editor: TullyFoote
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.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Porting nodes to nodelets

Description:

Tutorial Level: BEGINNER

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>

Wiki: nodelet/Tutorials/Porting nodes to nodelets (last edited 2018-11-06 11:43:32 by Markus Bader)