[Documentation] [TitleIndex] [WordIndex

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


Tutorial Level: BEGINNER

Work in progress...(see nodelet_tutorial_math for an example)

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

2019-04-20 12:59