Passing Command-line Arguments to Python Nodes via ROS Launch
COM2009 Assignment #1 Checkpoint
It helps if you've already completed Assignment #1 Part 1 before working on this.
Having built a CLI for our Python Node on the previous page, we'll now look at how this all works when we call a node using roslaunch
instead.
-
First, create a launch file called
publisher_cli.launch
. It probably makes sense to create this inside yourpart1_pubsub
package: -
Inside this add the following:
<launch> <arg name="roslaunch_colour" default="Black" /> <arg name="roslaunch_number" default="0.999" /> <node pkg="tuos_examples" type="publisher_cli.py" name="publisher_cli_node" output="screen" args="-colour $(arg roslaunch_colour) -number $(arg roslaunch_number)" /> </launch>
Here, we are specifying command-line arguments for the launch file using
<arg>
tags, as discussed earlier:Next, we use a
<node>
tag to launch thepublisher_cli.py
node from thetuos_examples
package. All of that should be familiar to you from Part 1. What's new here however is the additionalargs
attribute:This is how we pass the
roslaunch
command-line arguments into the CLI of our ROS Node:-colour
and-number
are the command-line arguments of the Python Noderoslaunch_colour
androslaunch_number
are the command-line arguments of the launch file
-
Run the launch file without passing any arguments first, and see what happens:
-
Then try again, this time setting alternative values for the available command-line arguments: