Ask Your Question

roslaunch command line args

asked 2017-12-08 06:58:33 -0600

Leonid gravatar image

updated 2018-09-14 12:32:08 -0600

jayess gravatar image

Read through all the tutorials, but couldn't find the answer to this one. I have a ROS node executable, which I can run like this:

./my_node -arg1 -arg2

I can also start it using roslaunch and a my_launch.launch file:

roslaunch my_launch.launch

How do I specify arg1 and arg2 when starting using roslaunch? I.e. how do I get arg1 and arg2 to show up in argc and argv?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-12-08 09:34:42 -0600

If you using raw command line arguments then you'll need to use the args attribute of the node tag in your launch file are described in the node tag documentation.

The example below will work in your case:

  <node pkg="my_package" type="my_node" name="node_instance" args="-arg1 -arg2" />
edit flag offensive delete link more

answered 2017-12-08 10:04:21 -0600

Leonid gravatar image

updated 2018-09-14 02:42:57 -0600

ahendrix gravatar image

Thanks for the responses. I'd just like to document what I found. Like PeteBlackerThe3rd said, you can hardcode command line args in your launch file:

   <node pkg="my_package" type="my_node" name="node_instance" args="-arg1 -arg2" />

You can also specify arguments on the actual command line (this is what I was trying to get at with my question), but that requires an extra step. The launch file would look like this:

   <arg name="my_args"/>
   <node pkg="my_package" type="my_node" name="node_instance" args="$(arg my_args)"/>

And your roslaunch command would look like this:

> roslaunch my_launch.launch my_args:="-arg1 -arg2"
edit flag offensive delete link more


@Leonid how did you use these arguments in your node? Like args[0], args[1] etc. ?

surabhi96 gravatar image surabhi96  ( 2018-09-13 03:06:57 -0600 )edit

I used getopt to parse them, but yes, you can access them through argc and argv in your main().

Leonid gravatar image Leonid  ( 2018-09-13 08:38:30 -0600 )edit

@Leonid I am using a python script and am accessing them through sys.argv[0]. But before that, I'm getting this error: Invalid roslaunch XML syntax: not well-formed (invalid token): line 3, column 90 The traceback for the exception was written to the log file

surabhi96 gravatar image surabhi96  ( 2018-09-13 18:26:48 -0600 )edit

I've edited this answer to add the appropriate quote marks, as noted in

ahendrix gravatar image ahendrix  ( 2018-09-14 02:43:31 -0600 )edit

@ahendrix Thanks!

surabhi96 gravatar image surabhi96  ( 2018-09-16 18:39:01 -0600 )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: 2017-12-08 06:58:33 -0600

Seen: 14,697 times

Last updated: Sep 14 '18