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

setting a param from the launch file doesn't work with string

asked 2014-09-24 03:23:24 -0600

MosheS gravatar image

Hi,

I'm trying to set a param using the launch file like so:

<node name="right_sensor" pkg="action" type="input_signal" output="screen" >
    <param name="port" value="55551" />
    <param name="signal_name" value="right" />
</node>

In my code I have this:

  string port, signal_name;

  ros::NodeHandle private_node_handle_("~");
  private_node_handle_.param("signal_name", signal_name, string("signal"));
  private_node_handle_.param("port", port, string("55555"));

  ROS_INFO("PORT: %s", port.c_str());
  ROS_INFO("Signal Name: %s", signal_name.c_str());

It appears that the "port" is not transferred correctly (I get "55555").

Only "signal_name" is correct.

BTW, if I add a letter before the value of the param in port (e.g. "a55551), it will be ok.

Can anyone assist? Is this a bug or a feature?

Thanks,

edit retag flag offensive close merge delete

Comments

1

Did you try setting the type in the launch file with type="string"?

BennyRe gravatar image BennyRe  ( 2014-09-24 04:14:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2014-09-24 12:01:31 -0600

bvbdort gravatar image

updated 2014-09-24 12:03:03 -0600

55551 will be resolved to integer and port is expecting string, so port is getting default value. Specifying the type attribute will solve it.

From wiki roslaunch XML param

If you don't specify the type, roslaunch will attempt to automatically determine the type. These rules are very basic:

numbers with '.'s are floating point, integers otherwise;

"true" and "false" are boolean (not case-sensitive).

all other values are strings

edit flag offensive delete link more

Comments

Just to complement, adding type="string" to the launch file solves the problem when you set the parameter in that file. However, if you don't, the default value will be used. Hence, you could also explicitly call private_node_handle_.param<string>(...) to guarantee type safety at compile time.

Murilo F. M. gravatar image Murilo F. M.  ( 2014-09-24 16:56:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-09-24 03:23:24 -0600

Seen: 1,241 times

Last updated: Sep 24 '14