Ask Your Question

Passing arguments to launch file from Python API

asked 2016-06-15 12:34:40 -0500

juesato gravatar image

I'd like to do the equivalent of

roslaunch a.launch foo:=bar

in Python. Right now I'm using the ROSLaunchRunner, but that's not important to me if there's another way to do this.

edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted

answered 2018-03-13 09:39:00 -0500

Cerin gravatar image

It's not well, documented, but the roslaunch.core.Node class supports all the same parameters that the rosrun and 'roslaunch' commands support.

So, if you were to launch a node with:

rosrun mypackage _param1:=123 _param2:=abc

you could do the same thing from Python with:

import roslaunch

node = roslaunch.core.Node(
    args='_param1:=123 _param2:=abc',
launch = roslaunch.scriptapi.ROSLaunch()
process = launch.launch(node)
# do stuff
edit flag offensive delete link more


this doesn't work with launch files.

mugenzebra gravatar imagemugenzebra ( 2019-03-11 14:29:19 -0500 )edit

answered 2018-06-19 16:41:40 -0500

lucasw gravatar image

updated 2018-06-19 16:51:23 -0500

I found a hacky method that works at least in kinetic and possibly a few versions earlier- the roslaunch api for lunar looks to support arguments properly so that ought to be used (and hopefully it gets backported).

(I also described this partially and probably confusingly in )

import sys
# override the sys.argv in roslaunch with our own,
# make sure there are no blank '' entries
sys.argv = ['roslaunch', 'foo', 'bar.launch', 'arg1:=234', etc.]
import roslaunch

(In the api it looks like roslaunch.main(argv) ought to work without the sys.argv overriding, but I think the call to main in __init__ keeps that from working?)

It is then possible to put the above into a node and then launch that node like @Cerin describes, and furthermore make the list of args set by args from the scriptapi call (though making that generic to any arbitrary arguments to arbitrary launch files is more work again).

Some similar questions:

programmatic-way-to-stop-roslaunch (already mentioned above)





Also programmatic rosrun questions:


TBD add some others

edit flag offensive delete link more

answered 2016-06-16 07:55:51 -0500

I've never had much luck digging into ROSLaunchRunner.... would it be okay if you run the roslaunch file as a subprocess of the Python script? You could use os.system or subprocess.Popen with the exact roslaunch command that you want run. I've done that quite a few times successfully.

edit flag offensive delete link more

answered 2019-07-18 11:16:06 -0500

Wang Shengyu gravatar image

updated 2019-07-18 11:47:11 -0500

Just follow the code below:

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)



edit flag offensive delete link more


Code only answers should be discouraged. Can you please update your question with an explanation

jayess gravatar imagejayess ( 2019-07-18 11:32:56 -0500 )edit

I think code only answer is enough for this question. And you can click the reference to get further info.

Wang Shengyu gravatar imageWang Shengyu ( 2019-07-18 11:46:00 -0500 )edit

answered 2016-12-21 17:35:21 -0500

vinaykumarhs2020 gravatar image

This might be a too late. You can use roslaunch api to do this. See this example for basic usage:

To remap arguments, as you have asked, you can use args and remap_args as mentioned here:

edit flag offensive delete link more


That does not show how to pass in arguments...

Cerin gravatar imageCerin ( 2018-03-13 09:20:27 -0500 )edit

It does now, but arguments only work in lunar and after.

lucasw gravatar imagelucasw ( 2018-06-19 16:17:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-15 12:34:40 -0500

Seen: 1,971 times

Last updated: Jul 18