ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Multiple nodelets in the same package

asked 2018-08-29 16:05:39 -0500

I am trying to create a package that performs multiple computer vision tasks. I want to nodeletize both tasks to take advantage of zero-copying of the images. Working off the examples below I have been able to create a single nodelet successfully, but am running into naming issues when trying to catkin_make my package with a second nodelet.

I was surprised that I couldn't find any examples of packages with multiple nodelets to reference. Is this because its bad practice?

If not does anyone have an example of what the CMakeLists.txt and nodelets.xml files should look like for multiple nodelets?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-08-29 19:31:55 -0500

KenYN gravatar image

updated 2018-08-29 19:32:15 -0500

One thing that helps me is to write each nodelet/node so that it can be built either (or indeed both!) ways. Put all your functionality into a class with a constructor that takes both the public and private node handles.

We then have this template that generates a thin interface class between the Nodelet code and our implementation:

namespace nodelet_helper{
    template<typename T>
    class TNodelet: public nodelet::Nodelet
        TNodelet() {};

        void onInit() {
            NODELET_DEBUG("Initializing nodelet");

            m_theT = std::unique_ptr<T>(new T(getNodeHandle(), getPrivateNodeHandle()));

        std::unique_ptr<T> m_theT;
} // End nodelet_helper namespace

Then, to use it we have code like this:

namespace my_vision_tasks {
    using VisionTaskOneNodelet = nodelet_helper::TNodelet<VisionTaskOne>;
    using VisionTaskTwoNodelet = nodelet_helper::TNodelet<VisionTaskTwo>;

PLUGINLIB_EXPORT_CLASS(my_vision_tasks::VisionTaskOneNodelet, nodelet::Nodelet)
PLUGINLIB_EXPORT_CLASS(my_vision_tasks::VisionTaskTwoNodelet, nodelet::Nodelet)

Finally, the XML is:

<library path="lib/libstructure_from_motion_v2_nodelet">
  <class name="my_vision_tasks/VisionTaskOneNodelet" type="my_vision_tasks::VisionTaskOneNodelet" base_class_type="nodelet::Nodelet">
    <description>Task one</description>

  <class name="my_vision_tasks/VisionTaskTwoNodelet" type="my_vision_tasks::VisionTaskTwoNodelet" base_class_type="nodelet::Nodelet">
    <description>Task two</description>
edit flag offensive delete link more

answered 2018-11-06 18:59:37 -0500

surabhi96 gravatar image

updated 2018-11-06 19:00:33 -0500

In addition to what @KenYN said, You will also have to modify your launch file

  <node pkg="nodelet" type="nodelet" name="manager_"  args="manager" output="screen" />

  <node pkg="nodelet" type="nodelet" name="NodeletOne" args="load my_vision_tasks/VisionTaskOneNodelet manager_" output="screen" >    

  <node pkg="nodelet" type="nodelet" name="NodeletTwo" args="load my_vision_tasks::VisionTaskTwoNodelet manager_" output="screen" >    

edit flag offensive delete link more

Question Tools



Asked: 2018-08-29 16:05:39 -0500

Seen: 1,430 times

Last updated: Nov 06 '18