Ask Your Question

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

asked 2012-12-05 01:21:24 -0500

Random-I-Am gravatar image

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;
    local_nh.getParam("haarcascade_filename_list", 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: " <<; 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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2012-12-05 01:27:25 -0500

Lorenz gravatar image

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.

edit flag offensive delete link more



If you just want to retrieve the resouce name, but not load the actual file, you can use ros::package::getPath -

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

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: 2012-12-05 01:21:24 -0500

Seen: 992 times

Last updated: Dec 05 '12