-
Notifications
You must be signed in to change notification settings - Fork 914
-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pass in a numerical string as arg param to C++ node #1339
Comments
Double quotes with single inner quotes works for rosparam set, the outer quotes are stripped of, and the inner quotes clue rosparam that the type is string:
But using that as an arg to a C++ node and the string is '98432', with the single quotes as characters in the string, but in a python node the quotes are stripped and the type is correctly determined to be a string. rosparam get on a string with single quotes yields
|
Double + single quotes doesn't work for roslaunch <param> tags (regardless if the node using the param is C++ or python), the inner single quotes become part of the string as with args to a C++ node. ( |
…mmand line arg test is needed for that
…, so numerical strings get stored like they do through rosparam set and rospy init ros#1339
I don't see it in your example invocations, but is |
Would the argument for going the other way and making With some further experiments with quotes within strings it looks like there is an additional issue:
So there is some code (in yaml parser not rospy?) that is looking for a leading quote regardless of a matching ending quote and then misinterprets and throws. Escaping the space and no outer quotes succeeds but loses the quotes:
rosparam get could be losing quotes that rosparam set preserved, I'll have to look at that later. |
Strings in yaml don't necessarily need quotes. That is probably why you don't see them in Not seeing quotes also doesn't necessarily mean it's not a string. |
I've noticed that rosparam prints quotes when it it is ambiguous:
(It would be convenient if |
We are encountering the same problem... |
For those looking for a work-around: std::string serial_number;
if (!nh->getParam("connect_serial_number", serial_number))
{
// When using rosrun the serial number is interpreted as an int and
// can't be forced into a string. See https://github.com/ros/ros_comm/issues/1339
int serial_number_int;
if (nh->getParam("connect_serial_number", serial_number_int))
serial_number = std::to_string(serial_number_int);
} First: try to get the parameter as a string. Then you can run the node and pass the argument as you would expect: rosrun my_package my_node _connect_serial_number:=190345 |
yeah, but that workaround has limitations... e.g. it won't work for strings with leading zeros.. |
If a numerical string like "4235" or "57.23" is set onto the parameter server as a command line argument to a C++ node then it is turned into type int or float on the parameter server and a getParam of type string will not get it.
It looks like the root of the issue is that setting a parameter with quotes that is a valid int or float turns into an int or float:
I'm using kinetic on Ubuntu 16.04.
I also tried this with kinetic-devel, though got a
‘ros_steadytime’ is not a member of ‘ros’
error (even when bringing in the latest roscpp_core) so went back to d4788bc .(I experimented with adding unit tests here but I'm not sure how to quickly build and test them in a catkin tools build environment - it takes a long time to build and run many tests of test_roscpp, I can't selectively just do a few. How to build just
./devel/lib/test_roscpp/test_roscpp-params
and not run it or anything else? Extract the build line out of a verbose build/run of everything?)The text was updated successfully, but these errors were encountered: