ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
753 stars 913 forks source link

[rosrun] private param parsing as yaml #1153

Open guihomework opened 7 years ago

guihomework commented 7 years ago

in kinetic, it seems to be impossible to enforce to pass a string to a private parameter in rosrun

if myapp wants to get a string like so

std::string myvariable;
nh_private.getParam("myparam", myvariable);

this will return false when parsing / casting to a string if a number is given even if put in quotes

rosrun mypkg myapp _myparam:=123
rosrun mypkg myapp _myparam:="123"
rosrun mypkg myapp _myparam:='123'

I though I could force the param the same way as in service calls

rosservice call /my_service '!!str true'

but apparently rosrun does not parse private parameters as yaml

rosrun mypkg myapp _myparam:='!!str 123'

gets myvariable set to '''!!str 123'''

So the only solution I found is to handle the XmlRpc myself and convert INTs into a string if getType()==XmlRpc::XmlRpcValue::TypeInt

evenator commented 7 years ago

This is actually a roscpp bug, not a rosrun bug. The code in question is in param::init() in clients/roscpp/src/libros/param.cpp

jdlangs commented 6 years ago

It might be useful to have an exception thrown if the parameter function argument type doesn't match the value existing in the server.

More insidious than the getParam case are the NodeHandle::param functions, which silently give you the default value. It would have just saved me a good chunk of time if I had received an immediate error that the parameter type is mismatched with the template argument.