Rosanswers logo

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_kinect2/blob/master/kinect2_bridge/src/kinect2_bridge.cpp#L248 )

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


Originally posted by Crusty on ROS Answers with karma: 70 on 2016-06-07

Post score: 1


1 Answer 1


Rosanswers logo

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

rosrun kinect2_bridge kinect2_bridge _sensor:="'123456'"


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.

Originally posted by jarvisschultz with karma: 9031 on 2016-06-07

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Crusty on 2016-06-07:
I've tried `rosrun kinect2_bridge kinect2_bridge _sensor:='"123456"' and that didn't work. (ticks reversed compared to your answer)

Comment by jarvisschultz on 2016-06-08:
Ahh... you're totally right. It was more than just a hack, it was totally wrong! More info added to answer

Comment by Crusty on 2016-06-08:
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)

Comment by VictorLamoine on 2019-10-09:
In a roslaunch file you can force the type of a parameter: http://wiki.ros.org/roslaunch/XML#Setting_parameters


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.