ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

String parameter is ignored if numeric, why?

asked 2013-09-09 04:16:45 -0500

timm gravatar image

updated 2013-09-09 04:18:08 -0500

I am requesting a string parameter from the parameter server in ROS Groovy like this:

ros::NodeHandle node_ns("~");
std::string rotations;
node_ns.param<std::string>("rotations", rotations, std::string("0"));

When I run my ROS node with the following command line, everything works fine:

./bin/testnode _rotations:='90 -90 0'

i.e. if I check the value of the string "rotations", it is "90 -90 0". However, if I only input a single numeric value as the string's value,

./bin/testnode _rotations:='270'

the supplied value is ignored and "rotations" has its default value of "0". I think this occurs because the single value is treated as an integer instead of a string. Is this a bug? This can have pretty nasty consequences! I was debugging my code for over an hour trying to figure out why my supplied parameter value was being ignored although it had worked perfectly in other cases...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-10-10 07:33:28 -0500

timm gravatar image

I have not yet had the chance to try this out, but using !!str on the command line should enforce the argument to be treated as a string, as described here:

YAML uses "tags" to override types, where the YAML syntax may be ambiguous. Common tags are: !!str, !!int, !!float, !!seq and !!map. Most likely you will just need to know about !!str. YAML tags are difficult because ! has its own meaning in Bash, so you have to use single-quotes.

e.g.

./bin/testnode _rotations:='!!str 270'
./bin/testnode _rotations:='!!str 90 -90 0'
edit flag offensive delete link more
1

answered 2013-09-09 09:37:43 -0500

kalectro gravatar image

I would guess that '270' is interpreted as a character. Try running

 ./bin/testnode _rotations:="270"

to tell your command line to interpret it as a string

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-09 04:16:45 -0500

Seen: 298 times

Last updated: Oct 10 '13