Now on ROS Indigo, I can get the list to an argument as follows:
rosrun pkg node _param:="[1, 2]"
This will put a list with two numbers on the param server.
It seems to be documented here: http://wiki.ros.org/ROS/YAMLCommandLine . Strings would be quoted by the other type of quotes than the one used to quote the whole list.
In rospy, it works out of the box:
print rospy.get_param("~param")[0]
In roscpp, the use is also as easy as:
std::vector<double> v;
pnh.param("param", v, std::vector<double>());
Problems can arise when you want to pass the array to the node using a roslaunch file - then the clasical "<arg>
and <param>
policy" won't work, since roslaunch doesn't know about list types and will convert the list to a single string. Since Lunar, you may use the construct <param name="param" type="yaml" value="$(arg param)" />
(documentation). In Indigo, you can achieve a similar result by <rosparam param="param" subst_value="True">$(arg param)</rosparam>
(documentation).
Originally posted by peci1 with karma: 1366 on 2018-01-25
This answer was NOT ACCEPTED on the original site
Post score: 7
Original comments
Comment by 2ROS0 on 2018-01-28:
<arg name="string_list" default="[this, is, list]"/>
<rosparam param="string_list" subst_value="True">$(arg string_list)</rosparam>
This shows the following error: requires the 'string_list' arg to be set
Comment by peci1 on 2018-01-28:
@2ROS0 Which ROS version? Did you try enclosing each of the three strings in single quotes?
Comment by 2ROS0 on 2018-01-28:
kinetic, I defaulted to the hack in @Markus Bader answer. I think I did try with the quotes but I'll try again in a bit and edit this comment
Comment by 2ROS0 on 2018-01-28:
yeah I tried with the whitelist example on the documentation you linked as is without any changes. It gives the same answer even though those are ints and not strings
Comment by peci1 on 2018-01-29:
@2ROS0 So does it work for you in the end?
Comment by 2ROS0 on 2018-01-29:
No, it seems there is a bug somewhere. I removed everything else from my launchfile and tried with a simple image_view
node as shown below but still same error. Is there someone that can check to see if the same error occurs to them? I am running ROS Kinetic
Comment by 2ROS0 on 2018-01-29:
Here is my basic launchfile:
<arg name="whitelist" default="[3, 2]"/>
<rosparam param="whitelist" subst_value="True">$(arg whitelist)</rosparam>
Comment by peci1 on 2018-01-29:
@2ROS0 The <arg>
tag has to be a direct child of the <launch>
element, and not inside the <node>
. Then it will work.
Comment by 2ROS0 on 2018-01-29:
@peci1 you should add the launchfile syntax to the wiki page about reading ros params if you don't mind because it is missing there
Comment by Andrew Price on 2020-02-10:
Has anyone gotten the
<param type="yaml"/>
syntax to work? It fails for me on Kinetic with:
Invalid <node> tag: Invalid <param> tag: Unknown type 'yaml'.
Param xml is <param name="ignore" type="yaml" value="$(arg ignore)"/>.
The rosparam
version does work, though.