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_pubsubpackage: -
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.pynode from thetuos_examplespackage. All of that should be familiar to you from Part 1. What's new here however is the additionalargsattribute:This is how we pass the
roslaunchcommand-line arguments into the CLI of our ROS Node:-colourand-numberare the command-line arguments of the Python Noderoslaunch_colourandroslaunch_numberare 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: