
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"
Originally posted by Leonid with karma: 163 on 2017-12-08
This answer was NOT ACCEPTED on the original site
Post score: 11
Original comments
Comment by surabhi96 on 2018-09-13:
@Leonid
how did you use these arguments in your node?
Like args[0], args[1] etc. ?
Comment by Leonid on 2018-09-13:
I used getopt to parse them, but yes, you can access them through argc and argv in your main().
Comment by surabhi96 on 2018-09-13:
@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
Comment by ahendrix on 2018-09-14:
I've edited this answer to add the appropriate quote marks, as noted in https://answers.ros.org/question/303339/adding-arguments-via-command-line-during-roslaunch/
Comment by surabhi96 on 2018-09-16:
@ahendrix Thanks!