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

Revision history [back]

This answer is for Melodic. You'll need to pass the arguments as individual entries in a Python list. To better understand this, take a look at the sample code in the API documentation (roslaunch/API Usage):

import roslaunch

cli_args = ['/home/mosaic/catkin_ws/src/robot/launch/id.launch','vel:=2.19']
roslaunch_args = cli_args[1:]
roslaunch_file = [(roslaunch.rlutil.resolve_launch_arguments(cli_args)[0], roslaunch_args)]

parent = roslaunch.parent.ROSLaunchParent(uuid, roslaunch_file)

parent.start()

cli_args is simply a Python list containing the launch file as list item 0 and arguments after 0, hence cli_args[1:]. Here's a modified version of their example to illustrate:

import roslaunch

arg0 = '/home/mosaic/catkin_ws/src/robot/launch/id.launch'
arg1 = 'vel:=2.19'
arg2 = 'udp_dest:=192.168.2.100'
arg3 = 'mode:=2048'
cli_args = [arg0, arg1, arg2, arg3]
roslaunch_args = cli_args[1:]
roslaunch_file = [(roslaunch.rlutil.resolve_launch_arguments(cli_args)[0], roslaunch_args)]

parent = roslaunch.parent.ROSLaunchParent(uuid, roslaunch_file)

parent.start()

(Note that you'll have to set the uuid for this to work. Just look at how they do it earlier in the document.)