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

Revision history [back]

click to hide/show revision 1
initial version

I just did this for one of my packages. Here is some example code:

void my_node::parseParams(ros::NodeHandle n) {
  XmlRpc::XmlRpcValue filters;
  n.getParam("filter", filters);
  ROS_ASSERT(filters.getType() == XmlRpc::XmlRpcValue::TypeStruct);
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = filters.begin(); it != filters.end(); ++it) {
    ROS_INFO_STREAM("Found filter: " << (std::string)(it->first) << " ==> " << filters[it->first]);
    // Do stuff with filters:
    ROS_INFO_STREAM("filter_cascade_1: in: " << filters[it->first]["in"]);
    ROS_INFO_STREAM("filter_cascade_1: filter: first_applied_filter: config_for_filter_1: " << filters[it->first]["filter"]["first_applied_filter"][0]);
  }
}

This works with xmlrpc structs which is what you get when you query arbitrary parameter namespaces. The iterator contains as it->first the keys of all the parameters found in the filter namespace: filter_cascade_1 and filter_cascade_2 and the it->second contains a xmlrpc struct of the parameters in that namespace. It is not really nice or convenient to use but I hope the example helps a bit.

I just did this for one of my packages. Here is some example code:

#include <XmlRpcValue.h>
...

void my_node::parseParams(ros::NodeHandle n) {
  XmlRpc::XmlRpcValue filters;
  n.getParam("filter", filters);
  ROS_ASSERT(filters.getType() == XmlRpc::XmlRpcValue::TypeStruct);
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = filters.begin(); it != filters.end(); ++it) {
    ROS_INFO_STREAM("Found filter: " << (std::string)(it->first) << " ==> " << filters[it->first]);
    // Do stuff with filters:
    ROS_INFO_STREAM("filter_cascade_1: in: " << filters[it->first]["in"]);
    ROS_INFO_STREAM("filter_cascade_1: filter: first_applied_filter: config_for_filter_1: " << filters[it->first]["filter"]["first_applied_filter"][0]);
  }
}

This works with xmlrpc structs which is what you get when you query arbitrary parameter namespaces. The iterator contains as it->first the keys of all the parameters found in the filter namespace: filter_cascade_1 and filter_cascade_2 and the it->second contains a xmlrpc struct of the parameters in that namespace. It is not really nice or convenient to use but I hope the example helps a bit.

I just did this for one of my packages. Here is some example code:

#include <XmlRpcValue.h>
...

void my_node::parseParams(ros::NodeHandle n) {
  XmlRpc::XmlRpcValue filters;
  n.getParam("filter", filters);
  ROS_ASSERT(filters.getType() == XmlRpc::XmlRpcValue::TypeStruct);
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = filters.begin(); it != filters.end(); ++it) {
    ROS_INFO_STREAM("Found filter: " << (std::string)(it->first) << " ==> " << filters[it->first]);
    // Do stuff with filters:
    ROS_INFO_STREAM("filter_cascade_1: in: " << filters[it->first]["in"]);
    ROS_INFO_STREAM("filter_cascade_1: filter: first_applied_filter: config_for_filter_1: " << filters[it->first]["filter"]["first_applied_filter"][0]);
  }
}

This works with xmlrpc structs which is what you get when you query arbitrary parameter namespaces. The iterator contains as it->first the keys of all the parameters found in the filter namespace: filter_cascade_1 and filter_cascade_2 and the it->second contains a xmlrpc struct of the parameters in that namespace. It is not really nice or convenient to use but I hope the example helps a bit.

Edit: Just to elaborate a bit more, the XmlRpcValue::TypeStruct is just a std::map<std::string,XmlRpcValue::TypeStruct>. If you look at the output of this line ROS_INFO_STREAM("Found filter: " << (std::string)(it->first) << " ==> " << filters[it->first]); it should be quite clear how to use it I hope. Took me a few hours to find the right way of doing this so if you have any problems, just let me know.