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

Revision history [back]

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of ns then continue
    ... remove ns from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 2)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of ns then continue
    ... remove ns from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 2)
3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of ns then continue
    ... remove ns base_namespace from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of ns base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "home";  
"/home";   // don't forget the leading slash

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split the key into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "/home";   // don't forget the leading slash

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split the key keys[i] into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.

For C++ there is an answer involving XmlRpc that #q197304 suggests, it would I used #q189299 as a starting point:

XmlRpc::XmlRpcValue list1;
nh.getParam("/home", list1);
for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = list1.begin();
    it != list1.end(); ++it)
{ 
  ROS_INFO_STREAM(it->first);
  XmlRpc::XmlRpcValue list2 = it->second;
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it2 = list2.begin();
      it2 != list2.end(); ++it2)
  { 
    ROS_INFO_STREAM(it2->first);
    // how to get the value now?  could getParam("/home/" + it->first + "/" + it2->first)
    // but we ought to be great to have example code for that (maybe inside param.cpp http://docs.ros.org/kinetic/api/roscpp/html/param_8cpp_source.html ?)

able to get it directly. } }

What is maybe less efficient but uses more familiar standard C++ instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "/home";   // don't forget the leading slash

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split keys[i] into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.

For C++ there is an answer involving XmlRpc that #q197304 suggests, I used #q189299 as a starting point:

XmlRpc::XmlRpcValue list1;
nh.getParam("/home", list1);
for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = list1.begin();
    it != list1.end(); ++it)
{ 
  ROS_INFO_STREAM(it->first);
  XmlRpc::XmlRpcValue list2 = it->second;
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it2 = list2.begin();
      it2 != list2.end(); ++it2)
  { 
    ROS_INFO_STREAM(it2->first);
    // how to get the value now?  could getParam("/home/" + it->first + "/" + it2->first)
    // but we ought to be able to get it directly.
  }
}

What is maybe less efficient but uses more familiar standard C++ string operations instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "/home";   // don't forget the leading slash

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split keys[i] into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.

For C++ there is an answer involving XmlRpc that #q197304 suggests, I used #q189299 as a starting point:

XmlRpc::XmlRpcValue list1;
nh.getParam("/home", list1);
for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = list1.begin();
    it != list1.end(); ++it)
{ 
  ROS_INFO_STREAM(it->first);
  XmlRpc::XmlRpcValue list2 = it->second;
  for(XmlRpc::XmlRpcValue::ValueStruct::const_iterator it2 = list2.begin();
      it2 != list2.end(); ++it2)
  { 
    ROS_INFO_STREAM(it2->first);
    // how to get the XmlRpc::XmlRpcValue xml_rpc_value = it2->second;
    if (xml_rpc_value.getType() != XmlRpc::XmlRpcValue::TypeDouble)
      continue;

    const double value now?  could getParam("/home/" + it->first + "/" + it2->first)
    // but we ought to be able to get it directly.
= static_cast<double>(xml_rpc_value);
    ROS_INFO_STREAM(it2->first << " " << value);
  }
}

What is maybe less efficient but uses more familiar standard C++ string operations instead of xmlrpc is to use getParamNames to get all the parameters then search through them for the tree you want ('home') and populate your map of maps manually.

  std::vector<std::string> keys;
  nh.getParamNames(keys);

  // or provide via param, or ros::this_node::getNamespace();
  std::string base_namespace = "/home";   // don't forget the leading slash

  ROS_INFO_STREAM(ns);

  for (size_t i = 0; i < keys.size(); ++i)
  {
    ... if keys[i] doesn't have a substring match of base_namespace then continue
    ... remove base_namespace from keys[i]
    ... split keys[i] into a vector of strings using '/' as a delimiter
    ... test if there are more or less split keys than expected (!= 3)
    // populate the nested maps 
    ... create route_home[split_keys[0]] if it doesn't already exist, then
    route_home[split_keys[0]][split_keys[1]] = split_keys[2];
  }

I get "ERROR: YAML dictionaries must have string keys" so I have to use "1" and "2" instead of 1 and 2 for keys for your example.

It would be nice if there was a nh.getParamNames(keys, "/foo"); and it would only get the params under '/foo'.