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

Creating/Parsing a dictionary of dictionary params

asked 2014-11-12 12:12:24 -0500

jsenna gravatar image

updated 2014-11-18 14:58:59 -0500

Hi everyone,

I am looking for help with some slightly more complex parameters than normal. The main motivation for this question is I am creating a node that must handle multiple pieces of hardware, and I must pass it unique parameters for each hardware. The number of hardware pieces is not defined and so I must be able to have any number of hardware/params (e.g. can't do left_camera and right_camera params).

I found that with rosparam I can create a list or dictionary parameter, and then parse it with roscpp. From my research I think I need to create a dictionary of dictionaries, but unfortunately I haven't been able to figure out how to properly create/parse such a parameter.

Inside my launchfile I have something that looks like:

    <rosparam param="hardware">
        hw1: { param1: value, param2: value }
        hw2: { param1: value, param2: value }
        hw3: { param1: value, param2: value }
    </rosparam>

Based on the example here http://wiki.ros.org/roslaunch/XML/ros... I can see how to create a XmlRpcValue type, but I'm still unclear on how to parse a more complex param. Any help is appreciated! Also feel free to tell me if this is the wrong way to handle this situation in ROS, I'd like to try to stick to ROS standards as much as possible.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-11-18 15:41:03 -0500

ahendrix gravatar image

In Groovy and newer versions of ROS, roscpp has an API for retrieving a portion of the parameter tree as a std::map: http://wiki.ros.org/roscpp/Overview/P...

In python, retrieving a portion of the parameter tree is implicitly a dictionary.

edit flag offensive delete link more

Comments

Thanks for the response, however I don't think that will work for me since it only seems to support lists or dictionaries of primitive types. I need to access a list of dictionaries (don't know what type that would even be, probably XmlRpcValue?)

jsenna gravatar image jsenna  ( 2014-11-18 16:30:39 -0500 )edit
1

If you have nested dictionaries, you may need to parse by hand. I think a dict will have the XmlRpc::XmlRpcValue::TypeStruct type, and you can use the hasMember() and operator[] (std::string) to retrieve the inner XmlRpcValues from the map.

ahendrix gravatar image ahendrix  ( 2014-11-18 17:18:54 -0500 )edit
1

answered 2014-11-18 15:29:25 -0500

Wolf gravatar image

updated 2014-11-18 15:29:41 -0500

Its standard yaml, so you can nest dictonaries and arrays inside of each other; If you have an unknown number of known instances (hardware configs), I guess an array of dictonaries is what you are looking for, e. g.:

<rosparam param="hardware">
    [ { name: 'hw1', param1: 1.3, param2: false }, { name: 'hw2', param1: 1.7, param2: true  }, { name: 'hw3', param1: -1.3, param2: true  } ]
</rosparam>

Now you can iterate the array and the read out the params of interest for each hardware....

edit flag offensive delete link more

Comments

Thanks for the response, this does look like it will achieve what I want but I am still unsure about how to extract the parameters inside the list (examples I can find only deal with a list of primitives). Any chance you could provide a little code or pseudo-code snippet? Thanks

jsenna gravatar image jsenna  ( 2014-11-18 16:26:34 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-12 12:12:24 -0500

Seen: 4,852 times

Last updated: Nov 18 '14