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 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


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_EXPORT_CLASS macro
  • add <build_depend> and <run_depend> dependencies on nodelet in the package manifest.

  • 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


Here we define the Class of our Nodelet. It's a good practice to place the header file under include/package_name/.

NB: The usage of the namespace is a good practice but not mandatory, in the following example we will proceed with the namespace example_pkg

#include <nodelet/nodelet.h>

namespace example_pkg

    class MyNodeletClass : public nodelet::Nodelet
            virtual void onInit();



This file should be placed under the src/ folder of your actual package

// this should really be in the implementation (.cpp file)
#include <pluginlib/class_list_macros.h>

// Include your header
#include <example_pkg/MyNodeletClass.h>

// watch the capitalization carefully
PLUGINLIB_EXPORT_CLASS(example_pkg::MyNodeletClass, nodelet::Nodelet)

namespace example_pkg
    void MyNodeletClass::onInit()
        NODELET_DEBUG("Initializing nodelet...");


This file should be placed along with the package.xml file

<library path="lib/libMyNodeletClass">
  <class name="example_pkg/MyNodeletClass" type="example_pkg::MyNodeletClass" base_class_type="nodelet::Nodelet">
  This is my nodelet.


  <nodelet plugin="${prefix}/nodelet_plugins.xml" />


Launch file should be placed under the launch/ repertory of your package, you can create it if it does not exist.

  <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">

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