0
$\begingroup$

Rosanswers logo

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.

http://www.clearpathrobotics.com/assets/guides/ros/Nodelet%20Everything.html
https://github.com/ros/common_tutorials/tree/indigo-devel/nodelet_tutorial_math
http://wiki.ros.org/nodelet/Tutorials
http://wiki.ros.org/usb_cam

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?


Originally posted by shoemakerlevy9 on ROS Answers with karma: 545 on 2018-08-29

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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
    {
    public:
        TNodelet() {};

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

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

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

  <class name="my_vision_tasks/VisionTaskTwoNodelet" type="my_vision_tasks::VisionTaskTwoNodelet" base_class_type="nodelet::Nodelet">
    <description>Task two</description>
  </class>
</library>

Originally posted by KenYN with karma: 541 on 2018-08-29

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.