Ask Your Question
7

Yaml List to Parameter to Vector

asked 2017-05-18 16:45:27 -0500

conor.mcmahon gravatar image

updated 2017-05-18 17:00:29 -0500

Hi,

I've been trying to store a list of doubles in a yaml file, load it into the parameter server, and later pull it back out from the server into a std::vector<double> in a cpp file, on ROS Kinetic.

yaml syntax I've used:

param_name:       [ .546, -.546, -.546,  .546,  .724, .724]

I've been able to get the list up into the parameter server without issue (currently, just via a 'rosparam load' terminal command on the yaml file). 'rosparam get' commands in the terminal return the expected values from it once it's there. However, when I try to retrieve the parameter within the cpp file I run into issues:

std::vector<double> param_list
if( !nh_.getParam("/param_name", param_list) )
    ROS_ERROR("Failed to get parameter from server.");

compiles, publishes the error message and fails to populate the vector. I've had confusing issues in the past dealing with ambiguous ros parameter server types so I've also tried this with a vector of floats with the same result. I think that the syntax I've used on the retrieval end matches that demonstrated here: http://wiki.ros.org/roscpp/Overview/P...

Do I have to do something to explicitly cast the data as the right type when I load it into the parameter server from the yaml?

I've also been able to get the XmlRpc method demonstrated in the above link to work with the vector - partly. I can retrieve the data and assert the list itself to be an array:

XmlRpc::XmlRpcValue param_list;
if( !nh_.getParam("/param_name", param_list) )
    ROS_ERROR("Still failed...");
ROS_ASSERT(param_list.getType() == XmlRpc::XmlRpcValue::TypeArray);

but when I try to assert the values in the array to be doubles:

for (int32_t i = 0; i < param_list.size(); ++i) 
{
  ROS_ASSERT(param_list[i].getType() == XmlRpc::XmlRpcValue::TypeDouble);
}

I get an "assertion failed" error on running the program. If I output the values in the array they seem correct even when not asserted to be doubles, but I get compile errors about "ambiguity" when I try to assign them to another, non-XmlRpc value later on. Either way though I'd really rather avoid using XmlRpc at all if I can make the vector stuff work instead!

In the past I've had similar setups work, pulling data out of a yaml file to the parameter server and then into a cpp file, but haven't ever been able to get yaml lists to cpp vectors to work.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2017-05-18 18:09:45 -0500

ufr3c_tjc gravatar image

Your retrieval methods look correct, meaning it's most likely a problem with the parameter itself. This may be inconsequential, but try putting a zero in front of your decimal values, rather than starting with the period. My code looks identical to yours, but I use zeros in the parameters.

edit flag offensive delete link more

Comments

Wow, it looks like this did it, thanks!! Just made this change and it works as expected now.

conor.mcmahon gravatar image conor.mcmahon  ( 2017-05-18 18:13:26 -0500 )edit

Yeah sometimes it's the little things... Glad I could help!

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-05-18 18:17:03 -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

2 followers

Stats

Asked: 2017-05-18 16:45:27 -0500

Seen: 9,727 times

Last updated: May 18 '17