Yaml List to Parameter to Vector
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.