Ask Your Question
1

Reading vector from launch file does not work in Indigo

asked 2018-05-23 04:35:57 -0500

d.fenucci gravatar image

Hi to all,

I'm facing an issue while reading a vector parameter from launch file in ROS Indigo. I set the parameter in my launch file in the private namespace of my node as;

<param name="x0" value="[0.0, 0.0]"/>

And I'm trying to read it as described here or in this previous answer:

ros::NodeHandle nh("~");
std::vector<double> x0;
nh.getParam("x0", x0);

but if I try to print the size of the vector it tells me 0. From the roslaunch param documentation it seems that parameters which are not scalar numbers or literal booleans are interpreted as strings.

Why is there such inconsistency between the types that I can read from the parameter server and the parameters that I can set from a launch file? How can I solve this problem?

Thanks to all in advance.

edit retag flag offensive close merge delete

Comments

1

So just to clarify: does this work if you use:

<rosparam param="x0">[0.0, 0.0]</rosparam>
gvdhoorn gravatar image gvdhoorn  ( 2018-05-23 04:50:17 -0500 )edit

Yes, in this way it works. Thanks, I didn't notice the comment in the previous answer. Still, is there any reason for this inconsistency?

d.fenucci gravatar image d.fenucci  ( 2018-05-23 04:59:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-09-17 14:06:11 -0500

Link gravatar image

Arrays need to be passed using rosparam instead of the normal param which is only able to accept scalar values or strings. The normal param has no way to tell the difference between a string and an array so it is always interpreted as a string. Since rosparam expects YAML syntax it is able to handle arrays. It can also handle dictionaries and others things specifiable in YAML syntax.

In your case it would look like this:

<rosparam param="x0">[0.0, 0.0]</rosparam>

Thanks to @gvdhoorn for answering this in a comment. I tried to expand on it and explain why rosparam was needed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-05-23 04:35:57 -0500

Seen: 734 times

Last updated: Sep 17 '18