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

Running ROS node with a numeric parameter passed as string doesn't work.

asked 2016-06-07 09:19:03 -0600

Crusty gravatar image

updated 2016-06-07 09:33:54 -0600

I am trying to run the IAI Kinect2 Bridge node as follows, in order to use multiple sensors:

$ kinect2_bridge _sensor:=1234567890

But the node does not recognize the provided sensor ID and falls back to default. The issue here seems to be, that ROS parses this parameter as number (and stores it as an int?) without me being able to force it being a string.

This code: priv_nh.param("sensor", sensor, std::string(""));

Then tries to read this parameter, but in all subsequent code, sensor.empty() is true. Seems that the parameter is an int, then fails the type check and gets ignored. (Source from here: https://github.com/code-iai/iai_kinec... )

How can I force passing _sensor:=.... as a string, despite it being only numbers without using a launch file?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-06-07 11:55:01 -0600

updated 2016-06-08 08:00:35 -0600

This seems like a bit of a hack, but I'll bet the following would work:

rosrun kinect2_bridge kinect2_bridge _sensor:="'123456'"

EDIT

The above "hack" does indeed trick the parameter into being interpreted as a string. However, this only works because adding the extra set of quotes means the inner value can't be converted into an int32 by boost::lexical_cast. So you end up with a string parameter with an extra quote character on both ends (which is not what is really wanted, or needed). Relevant lines of code in param.cpp.

Bottom line: not sure how to produce OP's goal. A launch file could certainly fix the issue. Alternatively, the kinect2_bridge package could be patched to expect the device serial number to be an int rather than a string. All of my Kinect2 devices have purely numeric serial numbers, so I'd expect this would work.

edit flag offensive delete link more

Comments

I've tried `rosrun kinect2_bridge kinect2_bridge _sensor:='"123456"' and that didn't work. (ticks reversed compared to your answer)

Crusty gravatar image Crusty  ( 2016-06-07 13:46:23 -0600 )edit

Ahh... you're totally right. It was more than just a hack, it was totally wrong! More info added to answer

jarvisschultz gravatar image jarvisschultz  ( 2016-06-08 07:55:15 -0600 )edit

Thanks a lot, I guess I need to try with a launch file then, which is a bit of a problem since I am currently running the binary directly, rather than via the roslaunch / rosrun infrastructure. (The binary is compiled elsewhere and deployed onto a machine without local ROS installation)

Crusty gravatar image Crusty  ( 2016-06-08 10:16:32 -0600 )edit

In a roslaunch file you can force the type of a parameter: http://wiki.ros.org/roslaunch/XML#Set...

VictorLamoine gravatar image VictorLamoine  ( 2019-10-09 04:27:04 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2016-06-07 09:19:03 -0600

Seen: 1,379 times

Last updated: Jun 08 '16