0
$\begingroup$

Rosanswers logo

I have a YAML file with a structure like the following:

field_a:
   field_a1: {field_b1, field_b2, ..., field_bM}
   field_a2: {field_b1, field_b2, ..., field_bM}
   ...
   field_aN: {field_b1, field_b2, ..., field_bM}

where field_a and field_bj are known a priori for all j, but field_ai are frequently changed by the user (i.e. can't be hard coded).

If I try to retieve the parameters field_ai using the C++ method getParam(...) or the command line rosparam get /field_a, what I get is everything in the tree hierarchy where /field_a is the root.

Is there a way to retrieve only the names of these field_ai and not their values? I could create another list with those names, but it not scale very well...

Thank you for your help!


Originally posted by alextoind on ROS Answers with karma: 217 on 2015-06-28

Post score: 0

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

You can definitely try to parse this manually with XMLRPC (or probably with yaml-cpp).

What you have here should probably be a std::map of std::pair<std::string, std::vector<T>>, but this is not supported, as far as I know. Simpler types work.

If you would choose python, you could use the rospy.get_param_names() function.


Originally posted by mgruhler with karma: 12390 on 2015-06-30

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

You can parse the XmlRpcValue after doing getParam on field_a. ROS' version of XmlRpcValue adds an iterator type and begin()/end() calls, so you can iterate over a struct.

If in doubt, check the header in /opt/ros/XXX/include/XmlRpcValue.h for the API, not the official (non-ROS) docs.


Originally posted by dornhege with karma: 31395 on 2015-06-30

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by mgruhler on 2015-07-03:
You're obviously right with checking the header in /opt/ros. I took the link which is linked from the ROS wiki Parameter Server page. Maybe we should put this note in there as well...

Comment by dornhege on 2015-07-03:
Updated. .

$\endgroup$
0
$\begingroup$

Rosanswers logo

Thanks to both! I did not think about XmlRpc and the hint of using the iterator works like a charm!

This is the code for the example above:

std::vector<std::string> field_names;
XmlRpc::XmlRpcValue list;

if (!node_handle_.getParam("/field_a", list)) {
  ROS_ERROR("Can't find '/field_a' in the YAML configuration file.");
  return;
}

for (auto it = list.begin(); it != list.end(); it++) {
  field_names.push_back(it->first);
}

For the sake of completeness it->second is the the nested list {field_b1, field_b2, ..., field_bM}.


Originally posted by alextoind with karma: 217 on 2015-07-02

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.