Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

Launch Files

< Back to ROS Beginner tutorials
What are launch files?
First Launch file
Coding
XML Tags
Launch a Node
Attributes
Creating user passed arguments
Attributes
Setting an environment variable
Attributes
Setting parameters on ROS Parameter server
Attributes
Substitution arguments
Environment variables
Finding packages
Arguments
Evaluated python expressions
Conditional statements and grouping
Additional
Configuring the Debugger levels of launched nodes
Using configuration files

What are launch files?

Ever though that there are just too many terminals to open and too much to type (and remember) everytime to get some things done ? Well, launch files are there exactly to solve that problem, and more. The command that we use to locate and launch such files is roslaunch.

Just one launch file can handle all of the following:

  • Starting of the roscore, if there isn't one running already
  • Launching any number of nodes with a customisable argument list
  • Access parameters on the ROS parameter server easily
  • Running key ROS components (we'll learn more about this in later pages)

A few things to remember about them is that:

  • All launch files have a ".launch" extension and are stored in a folder named "launch" in your package.
  • roslaunch is the command to run such files. You can find more about this here.
  • They are programmed using XML based language, thus most of it are just tags. A complete list could be found here, but this page has brief description and information about the most common and essential ones (in coming sections)

Let's create our first launch file

First Launch file

Coding

Code here

Follow these steps

  1. Create a folder named launch in your package directory and create a launch file (we'll name it "FirstLaunch.launch"):
    • roscd intro_pkg1
    • mkdir launch
  2. Open and write the following code into "FirstLaunch.launch" file:
    • Begin the <launch> tag
      • All the code inside the launch file must be written into this tag
    • All nodes that have to be launched use the <node> tag (more about this in the tags section).
    • End the </launch> tag
Code here

That's it. Now you can open a terminal and run the following command to run roscore and the node:

  • roslaunh intro_pkg1 FirstLaunch.launch

This will run both the debugger scripts (C++ and Python) in the same terminal window on two new tabs. Check their outputs.

FirstLaunch.launch code

XML Tags

All tags here. Entire launch file code must be inside <launch> ... </launch> tag.

Launch a Node

We use the <node> tag for that.

Attributes

The primary attributes of this tag are:

  • name: Name under which the Node will register with the ROS server. This is the name that will be shown in the launch menu, nothing else
  • pkg: Name of the package to which the node belongs.
  • type: The executable name of the node. If it's a python node, then it's simple the name of the python file, for C++ nodes, it's the name which you specify in add_executable function in the CMakeLists.txt file
  • respawn: If the node quits, then respawn it. There's another attribute named respawn_delay which will cause a respawn after a specified delay (in seconds)
  • required: If True then, if this node dies, kill entire roslaunch. This will kill all the things spawned due to the currently running roslaunch command.
  • args: Pass these arguments as additional arguments to the node (suffix arguments).
    • Python nodes launched using this method receive two additional arguments in the end, __name:=Node_name and __log:=Log_file_location.
  • launch-prefix: allows you to add text before the launch command. Ideal to launch nodes in separately created terminals using command like gnome-terminal command.
  • output: let's you direct output to a "log" file or the "screen"
Complete list here.

I've already explained how to set logger levels using a launch file on this page (you could alternatively check Additional > Configuring the Debugger levels of launched nodes).

Creating user passed arguments

  • We define these things using the <arg> tag.
  • We use "$(arg foo)" to substitute the value of the argument 'foo' in the launch file.
  • During calling the roslaunch, they're assigned using arg1:=value separated with spaces.

Attributes

The primary attributes of this tag are:

  • name: Name of the argument
  • default: Default value in case nothing is assigned from the call
  • value: Argument value which is a constant and cannot be overwritten
  • doc: Documentation, information about the argument

Setting an environment variable

We use the <env> tag to create an environment variable for the launch.

Attributes

The attributes for this tag are:

  • name: The name of the tag
  • value: The value of the variable

Setting parameters on ROS Parameter server

We use the <param> tag to setup the parameters on the parameter server.

Attributes

The primary attributes are:

  • name: Name of the parameter.
  • value: The value of the parameter. If not specified, specify the binfile (binary file), textfile (text file) or command (executable command) otherwise.
  • type: The type of data. Options are: "int", "str", "double", "bool", "yaml". If not specified, it's implicitly assumed to an appropriate value,
  • command: Command whose output will be parsed as string and assigned to the parameter as value.

Substitution arguments

We can substitute the value of variables using this method. Full list about this is here. There's a brief recap given below

Environment variables

More on this here
  • We use $(env ENV_VARIABLE) to directly substitute the value of ENV_VARIABLE at the place. In case the variable is not defined before the call, the roslaunch fails.
  • We use $(optenv ENV_VARIABLE default_value) to substitute the value of ENV_VARIABLE at the place. In case the variable is not defined, the string at the place of default_value is used (by default it's an empty string).

Finding packages

More on this here
  • Use $(find foo) and it will be substituted with the output of command rospack find foo.

Arguments

More on this here
  • Use $(arg foo) to substitute for the value of argument foo at the place called.

Evaluated python expressions

More on this here
  • Use $(eval <expression>) to substitute the result of <expression>. The expression must be a python expression (could be mathematical as well).
  • All substitutions are available as functions within eval as well.

Conditional statements and grouping

Conditional statements available are if and unless (negated if). They're most frequently used in groups. Example here.

Groups are formed using the <group> tag. Use the attribute:

  • if: If the assigned value evaluates to true or 1, the group is executed. Else it's left out.
  • unless: If the assigned value evaluates to false or 0, the group is executed. Else it's left out.

Additional

Configuring the Debugger levels of launched nodes

Using configuration files

ROS logger is made on top of log4cxx and log4j libraries. These use configuration files. The default configuration file used by ROS (for C++) is present in $ROS_ROOT/config/rosconsole.config (basically, /opt/ros/melodic/share/ros/config/rosconsole.config if you have a standard installation). You can create a folder named "config" in your package and redeclare the variables. More on this for C++ here and for Python here. Here's a short summary of what to do:

  • For C++
    • Set the value of log4j.logger.ros.intro_pkg1 to DEBUG in the file rosconsole_cpp.conf (stored in the config directory of the package).
      • You could choose any name for the ".conf" file, rosconsole_cpp is just an example.
    • Assign an environment variable named "ROSCONSOLE_CONFIG_FILE" to the path of the rosconsole_cpp.conf file in the launch file.
  • For Python
    • Open the directory /opt/ros/melodic/etc/ros/ and open the file named python_logging.conf (stored in the config directory of the package).
    • Copy the contents into a config file that you made for this (let it be rosconsole_python.conf). Make all the modifications that you want to.
      • Again, the name of the ".conf" file can be anything
    • Then set the environment variable "ROS_PYTHON_LOG_CONFIG_FILE" to the path of the rosconsole_python.conf file in the launch file.

Note that the configuration files have an extension ".config" or ".conf", you could use either but, just maintain the same naming standard throughout.

An example is given below

Launch file above


You'll learn more about launch files later on, for now you can skip this section and come back later if you don't completely get this.

  • A configuration file tells the libraries what to do (settings to be applied).
  • For C++, the file is stored in /opt/ros/melodic/share/ros/config/rosconsole.config is used and the environment variable ROSCONSOLE_CONFIG_FILE can be used to override the file location.
  • For Python, the file stored in /opt/ros/melodic/etc/ros/python_logging.conf is used and the environment variable ROS_PYTHON_LOG_CONFIG_FILE can be used to override the file location.

Note that the override is on the file location hence the complete list of contents must be available in the ".conf" file that you make. In C++ there are just two and there exist internal definitions, so you can omit the first one (log4j.logger.ros) can be omitted, but for Python, you have to declare the entire thing. It's best that you come here every time you want to change the logger levels for C++ and Python and read this text block.

For more on C++ config file, check out this page (Scroll to section named "2. Configuration")

You can set the environment variables however you want, going through launch files is just one method. You can come back here always so no need to remember these.

< Back to ROS Beginner tutorials
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse