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

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
2

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]"

list_points.py

#!/usr/bin/env python

import rospy

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

renderer.launch

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

Comments

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

2 followers

Stats

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

Seen: 3,210 times

Last updated: Oct 15 '16