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

ROS parameters - understanding of a line code

asked 2015-03-25 02:24:20 -0500

lilouch gravatar image

updated 2015-03-25 03:14:10 -0500


I found a code on the internet about SLAM and i'm not able to make it function. I need to understand what those code line do:

     std::string transport;
  std::string depth_topic;
     depth_topic = "camera/depth_registered/image_raw";
     ROS_INFO_STREAM("Could not retrieve depth_topic param");
    transport = "compressedDepth";
    ROS_INFO_STREAM("could not retrieve depth_image_transport param");

Because when i run the code i have all the INFO messages displayed on my terminal, so it means that it doesn't find topics from my camera. Indeed, on the book "a gentle introduction to ROS", they write the following sentence: The get function returns true if the value was read successfully and false if there was a problem, usually indicating that the requested parameters has not been assigned a value"

Does the code assume that we have a yaml file ? if not, how i can avoid this message, that is to say return true at the line nh.etParam.

Thank you

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-03-25 06:15:25 -0500

You need to set the parameters depth_topic and depth_image_transport on the Parameter Server (also see this tutorial.

The exact name depends on whether the node handle nh is a private node handle or not. Private node handles are initialized like this:

ros::NodeHandle nh("~");

... whereas the global node handle lacks the "~".

Assuming nh is a private node handle, and your node is called my_node, the full name of the parameters are /my_node/depth_topic and /my_node/depth_image_transport. You need to set these to the names of the topics you want to use. You can use either the rosparam command line tool before starting your node, set the parameters in the launch file, or add them to the rosrun call (just search for these things on the wiki). Use rosparam dump FILENAME.yaml to inspect the parameters currently stored on the parameter server and rostopic list to see what topics are advertised.

edit flag offensive delete link more


Thank for your answer Martin. The node is not private. So in the code i did the following stuff for example: nh.setParameters("depth_topic","/camera/depth_registered/image_raw"); I have no more the INFO message. But tell me if i'm mistaken, in the code, if the parameter is not set

lilouch gravatar image lilouch  ( 2015-03-25 22:06:10 -0500 )edit

, for example the depth_topic one, depth_topic = "camera/depth_registered/image_raw"; this part do that stuff that is to say initialize the parameter ? What does the line do in this case ?

Because Depth_topic is nowhere is the code. That's why i'm a bit confused.

I did all the tutorials.

lilouch gravatar image lilouch  ( 2015-03-25 22:06:25 -0500 )edit

answered 2015-03-25 22:09:14 -0500

2ROS0 gravatar image

In addition to @Martin 's answer and answering the additional questions you asked:

You must find out if your nodehandle nh is private or not. I don't know what you mean by node is not private. But assuming you meant the nodehandle is not private, that would mean that they are global parameters. And therefore just in the global namespace: /depth_topic /depth_image_transport

You do not get the ROS_INFO rosout because you are setting those parameters in your code. This has the same effect as the rosparam call or placing it in the launch file (as mentioned above). The line that sets the 'depth_topic' variable is a default value for the param in the case it hasn't been set.

If depth_topic is not used anywhere else then it is useless but the general use case would be that that param has some meaning. In this case, it looks like the node subscribes to the raw image topic of some sort of camera.

Run a rosnode info on the node and see what it subscribes to. You will likely find that topic.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-03-25 02:24:20 -0500

Seen: 360 times

Last updated: Mar 25 '15