Ask Your Question
4

listing parameters or using a dictionary

asked 2012-10-30 13:35:16 -0500

brice rebsamen gravatar image

updated 2014-01-28 17:14:06 -0500

ngrennan gravatar image

In C++, is there a way to list parameters on the parameter server, optionally those in a particular namespace? Alternatively, can I use a dictionary/map?

I want to put a mapping name/number in a yaml file loaded by roslaunch, and my node should be able to list the names and retrieve the associated number. rosparam list can do that, and associated with grep I can retrieve only the parameters I want. can I do that in C++ directly. the parameter server c++ API does not seem to provide that, or is it hidden? Can it be added in future releases?

I tried using a dictionary but it was expended in a list of parameters instead of being a dictionary data structure, i.e. those 2 yaml files yielded the same result

channel_numbers: {applanix: 0, radar: 1, trimble: 5, velodyne: 10}

and

channel_numbers:
  applanix: 0
  radar: 1
  trimble: 5
  velodyne: 10

I would like something like:

ros::NodeHandle nh("~");
vector<string> parameters = nh.list_parameters("channel_numbers");
// and then for each parameter in parameters get its value...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-10-31 02:16:41 -0500

dornhege gravatar image

updated 2015-04-30 15:28:15 -0500

Dirk Thomas gravatar image

The functionality is there by using XmlRpcValue versions of the getParam functions.

An example of how to get a list is available: http://www.ros.org/wiki/roscpp/Overvi... .

If you need more, i.e. dictionaries then refer to the XmlRpcValue docs.

TypeStruct is a dictionary. There is hidden functionality that the official docs do not list and afaik was added to ROS. For a dictionary there are begin() and end() functions that allow to iterate over the dict entries. You can find an example here: http://code.google.com/p/alufr-ros-pk...

edit flag offensive delete link more

Comments

The links end with a period accidentally. I don't have enough rep to edit.

gustavogoretkin gravatar imagegustavogoretkin ( 2015-04-30 14:48:01 -0500 )edit

I removed the dot.

Dirk Thomas gravatar imageDirk Thomas ( 2015-04-30 15:28:34 -0500 )edit

Thank you so much for sharing the example from alufr-ros package ;)

smihael gravatar imagesmihael ( 2015-08-18 07:57:03 -0500 )edit

Is there an updated link to the example. I couldn't find the TypeStruct example on the google code archive. I'm trying to print the params used by a given node.

blakejwc gravatar imageblakejwc ( 2018-04-17 09:09:18 -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

Stats

Asked: 2012-10-30 13:35:16 -0500

Seen: 2,359 times

Last updated: Apr 30 '15