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

array/list as command line argument in roslaunch file

asked 2016-10-15 11:34:04 -0500

ravijoshi gravatar image

I am drawing some points inside rviz. I want to pass these points as command line argument to roslaunch file. In other word, I looking for a way to enter command like below-

roslaunch render_points renderer.launch points:=[x1, y1, z1], [x2, y2, z2], [x3, y3, z3], [x4, y4, z4]

After this command, I should be able to get these points back inside python in similar way such as

points = rospy.get_param("~points", None)
# where points[0] is [x1, y1, z1] and points[1] is [x2, y2, z2] and so on..

I am not sure, whether it is possible or not. If not, please suggest some workaround to do the same.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-15 19:00:42 -0500

abrzozowski gravatar image

updated 2016-10-15 19:04:47 -0500

You can achieve what you want with passing points as string of arrays to the launch file.

For roslaunch args, see reference

My approach would be something like this:

$ roslaunch render_points array.launch points:="[11, 12, 13], [21, 22, 23], [31, 32, 33], [41, 42, 43]"

#!/usr/bin/env python

import rospy

if __name__=="__main__":
    points = rospy.get_param("~points", None)
    points = [[int(x.strip(' ')) for x in ss.lstrip(' [,').split(', ')] for ss in points.rstrip(']').split(']')]


<?xml version="1.0"?>
    <arg name="points" doc="description for this arg"/>
    <node pkg="render_points" type="" name="list_points" output="screen">
        <param name="points" value="$(arg points)"/>
edit flag offensive delete link more


Seems acceptable. Passing arguments as string is more flexible in this case. Thanks a lot. Appreciate it.

ravijoshi gravatar image ravijoshi  ( 2016-10-15 22:53:28 -0500 )edit

Question Tools



Asked: 2016-10-15 11:34:04 -0500

Seen: 3,208 times

Last updated: Oct 15 '16