Ask Your Question
1

Start a nodelet roscpp (Tegra SGM nodelet)

asked 2017-07-07 20:22:40 -0500

ashwath1993 gravatar image

updated 2017-07-07 20:24:36 -0500

I have a ros package which builds a image_proc like node for cuda SGM.
I have built the package and the nodelet is built. I am not sure how to run it. I have looked through the ros tutorials but there isn't a clear explanation of how to run a nodelet for a generic case.

The nodelet is exported as follows

#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(tegra_stereo::TegraStereoProc, nodelet::Nodelet)

After this, how do call this nodelet? Since I do not have a cpp file like the image_proc or stereo_image_proc to directly call the method. Is there a way to launch the nodelet or how do I launch it?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-07-07 22:49:27 -0500

Ed Venator gravatar image

updated 2018-03-10 09:50:41 -0500

There are three ways to run a nodelet:

  1. Run the nodelet standalone using roslaunch:

    <launch>
        <node name="my_nodelet" pkg="nodelet" type="nodelet" args="standalone tegra_stereo/TegraStereoProc" />
    </launch>
    

    or rosrun:

    rosrun nodelet nodelet standalone tegra_stereo/TegraStereoProc
    
  2. Run the nodelet as part of a nodelet manager. This is described on the ROS wiki here: http://wiki.ros.org/nodelet/Tutorials...

  3. Write a node wrapper, and then build and run it as you would a node. Here's what node wrapper code typically looks like:

    #include <ros/ros.h>
    #include <nodelet/loader.h>
    
    int main(int argc, char **argv){
      ros::init(argc, argv, "tegra_stereo_node");
    
      nodelet::Loader nodelet;
      nodelet::M_string remap(ros::names::getRemappings());
      nodelet::V_string nargv;
      std::string nodelet_name = ros::this_node::getName();
      nodelet.load(nodelet_name, "tegra_stereo/TegraStereoProc", remap, nargv);
      ros::spin();
    
      return 0;
    }
    

If any of these methods fail with an error message that pluginlib can't find your nodelet, make sure that you defined your nodelet in an XML file and exported it in your package.xml . Instructions to do so are on the ROS wiki here: http://wiki.ros.org/nodelet/Tutorials...

Bonus Methods

If you're willing to install another package, Southwest Research Institute created swri_nodelet to make some of these tasks easier.

  1. Run the nodelet standalone using roslaunch:

    <launch>
        <node name="my_nodelet" pkg="swri_nodelet" type="nodelet" args="tegra_stereo/TegraStereoProc standalone" />
    </launch>
    

    or rosrun:

    rosrun swri_nodelet nodelet  tegra_stereo/TegraStereoProc standalone
    
  2. Run the nodelet with a nodelet manager using roslaunch:

    <launch>
      <node name="manager" pkg="nodelet" type="nodelet" args="manager" />
      <node name="my_nodelet" pkg="swri_nodelet" type="nodelet" args="tegra_stereo/TegraStereoProc my_manager"/>
    </launch>
    

    (Note that this syntax makes it easy to switch launch files back and forth between manager and standalone using args.)

  3. Automatically create a node wrapper using swri_nodelet. This takes a couple of steps but saves you from writing boilerplate C++. Also, because it links the nodelet with the executable at compile time, you catch linker errors at compile time, instead of dealing with inscrutable runtime errors. Here's how to do it:

    In your nodelet's C++ file, replace the pluginlib macro with this:

    #include <swri_nodelet/class_list_macros.h>
    SWRI_NODELET_EXPORT_CLASS(tegra_stereo TegraStereoProc)
    

    In your CMakeList, build your library and add a nodelet executable like this:

    # (Add swri_nodelet to your find_package(catkin)
    
    add_library(my_nodelet_library src/TegraStereoProc.cpp)
    target_link_libraries(my_nodelet_library ${CATKIN_LIBRARIES})
    
    swri_nodelet_add_node(tegra_stereo_proc tegra_stereo TegraStereoProc)
    target_link_libraries(tegra_stereo_proc my_nodelet_library)
    
edit flag offensive delete link more

Comments

Thank you! This cleared a lot of confusions regarding running nodelets!

ashwath1993 gravatar image ashwath1993  ( 2017-07-12 03:21:05 -0500 )edit

Thank you. It is very clear. Are there any differences between these methods?

longlongago gravatar image longlongago  ( 2018-01-14 20:29:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-07-07 20:22:40 -0500

Seen: 729 times

Last updated: Mar 10 '18