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:
A few things to remember about them is that:
Let's create our first launch file
Follow these steps
roscd intro_pkg1
mkdir launch
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
All tags here. Entire launch file code must be inside <launch> ... </launch> tag.
We use the <node> tag for that.
The primary attributes of this tag are:
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).
The primary attributes of this tag are:
We use the <env> tag to create an environment variable for the launch.
The attributes for this tag are:
We use the <param> tag to setup the parameters on the parameter server.
The primary attributes are:
We can substitute the value of variables using this method. Full list about this is here. There's a brief recap given below
rospack find foo
.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:
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:
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.
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.