Ask Your Question
2

roslaunch command line args

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

Leonid gravatar image

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

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
5

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

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:

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

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

Leonid gravatar image

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

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:

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

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:

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

And your roslaunch command would look like this:

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

Comments

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

surabhi96 gravatar imagesurabhi96 ( 2018-09-13 03:06:57 -0500 )edit

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

Leonid gravatar imageLeonid ( 2018-09-13 08:38:30 -0500 )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 imagesurabhi96 ( 2018-09-13 18:26:48 -0500 )edit
1

I've edited this answer to add the appropriate quote marks, as noted in https://answers.ros.org/question/3033...

ahendrix gravatar imageahendrix ( 2018-09-14 02:43:31 -0500 )edit

@ahendrix Thanks!

surabhi96 gravatar imagesurabhi96 ( 2018-09-16 18:39:01 -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

Stats

Asked: 2017-12-08 06:58:33 -0500

Seen: 7,442 times

Last updated: Sep 14 '18