1

Rosanswers logo

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.


Originally posted by ravijoshi on ROS Answers with karma: 1744 on 2016-10-15

Post score: 1

ravi
  • 1,356
  • 2
  • 4
  • 11

1 Answers1

1

Rosanswers logo

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>

Originally posted by abrzozowski with karma: 290 on 2016-10-15

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by ravijoshi on 2016-10-15:
Seems acceptable. Passing arguments as string is more flexible in this case. Thanks a lot. Appreciate it.

abrzozowski
  • 190
  • 2