# NodeHandle::getParam() is unable to resolve Environmental variables

I have a launchfile in which I want to specify the path to a specific file, e.g. haarcascade_frontalface_alt.xml. Normally, I would just use the <param> tag like this:

<param name="haarcascade_filename" type="string" value="$(env ROS_ROOT)/../OpenCV/haarcascades/haarcascade_frontalface_alt.xml" />  and try to load it during initialization using NodeHandle::param(): ros::NodeHandle local_nh("~"); local_nh.param("haarcascade_filename", name_, std::string(""));  This is the way it is done for example in the face_detector stack. Assume that I now want to specify multiple files using a <rosparam> list: <rosparam param="haarcascade_filename_list">["$(env ROS_ROOT)/../OpenCV/haarcascades/haarcascade_frontalface_alt.xml", "morestrings.."]</rosparam>


This is the way I'm trying to load all the entries of the list:

    XmlRpc::XmlRpcValue my_xmlrpc_haarlist;
ROS_ASSERT(my_xmlrpc_haarlist.getType() == XmlRpc::XmlRpcValue::TypeArray);

for (int32_t i = 0; i < my_xmlrpc_haarlist.size(); ++i) {
ROS_ASSERT(my_xmlrpc_haarlist[i].getType() == XmlRpc::XmlRpcValue::TypeString);
haar_filename_list_.push_back(static_cast<std::string> (my_xmlrpc_haarlist[i]));
}


The problem is if I now do ROS_INFO_STREAM("Filename: " << supername_); and ROS_INFO_STREAM("Filename list: " << haar_filename_list_.at(0)); the results are not the same:

[ INFO] [1354712164.859028413]: Filename: /opt/ros/fuerte/share/ros/../OpenCV/haarcascades/haarcascade_frontalface_alt.xml
[ INFO] [1354712164.859087292]: Filename list: $(env ROS_ROOT)/../OpenCV/haarcascades/haarcascade_frontalface_alt.xml  How do I solve this issue? edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted This is a limitation of roslaunch. You cannot use $(env ...), \$(find ...) and similar expressions when setting parameters in a launch file using yaml syntax. Instead of expanding paths in roslaunch, I would instead specify them as package relative URIs, e.g. package://foo/bar to reference the file bar in ROS package foo. To resolve these URIs, you can use the resource_retriever package.

more

1

If you just want to retrieve the resouce name, but not load the actual file, you can use ros::package::getPath - http://ros.org/doc/fuerte/api/roslib/html/c++/namespaceros_1_1package.html#ae9470dd201aa4e66abb833e710d812a4

( 2012-12-05 02:23:49 -0500 )edit