Ask Your Question

get YAML list of dictionary items with ros::param in C++

asked 2018-05-18 09:55:10 -0600

ysl208 gravatar image

I would like to define a list of items in a yaml file which I read in with ros::param::param<t>()

It works fine if I read in a normal double or string:


if my yaml file is defined as:

 - {'id': 0, 'name': 'john', 'pos':[0,0,0]}
 - {'id': 1, 'name': 'anna', 'pos':[0,0,0]}
 - {'id': 2, 'name': 'bill', 'pos':[0,0,0]}

How can i access these with ros::param?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-18 10:35:26 -0600

aarushg gravatar image

You can see the Retrieving lists section in the end of this page

For your specific case, I think it's better if you can format your yaml file like :

 - id: 0 
   name: john 
   pos: [0,0,0]

 - id: 1 
   name: anna 
   pos: [0,0,0]

This way you can easily access the values as a dictionary after you fetch each item in the list as a XmlRpc::XmlRpcValue data type.

for (int i = 0; i < list.size(); i++) {
      XmlRpc::XmlRpcValue sublist = list[i];

This is just a raw example, you should always check for format errors before fetching data to avoid crashing your program. This is the best way that I know of, if anyone else can offer a better alternative, I'll be happy to learn.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2018-05-18 09:55:10 -0600

Seen: 959 times

Last updated: May 18 '18