ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROSLaunch and SRC

asked 2017-09-13 16:31:28 -0500

julimen5 gravatar image

updated 2017-09-14 11:18:52 -0500

Hi there, I'm new to ROS. I'm trying to understand how ROS works. I already did the tutorials but I really can't understand how does launch files works. I mean, sometimes I don't know how the launch files are connected with the logical part included in the src/ folder.

Thank you all!

edit retag flag offensive close merge delete

Comments

1

Welcome! I think that in order to get a better response, you should ask at least two separate questions. One about the launch files/source code connection and the other about RPLIDAR and SLAM as these are two different subjects. You can edit this question and then ask a new one as well.

jayess gravatar image jayess  ( 2017-09-13 17:43:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-09-14 15:07:37 -0500

jayess gravatar image

updated 2017-09-14 16:48:16 -0500

First, a very brief explanation of launch files and roslaunch. According to the wiki entry for roslaunch:

roslaunch is a tool for easily launching multiple ROS nodes locally and remotely via SSH...

Launch files provide a way, among other things, to launch a node (or nodes) with a single command:

roslaunch <package-name> <launch-file.launch>

Let's say that your package is called my_package with a node called my_node saved in the src folder. You can run (i.e., launch) your node by creating a launch file called my_node.launch like so:

<launch>
  <node pkg="my_package" type="my_node" name="my_node"/>
</launch>

and run it using

roslaunch my_package my_node.launch

The code inside of the launch file is just XML. The launch tag tells ROS that this is a launch file (they don't have to have a .launch file extension) and the node tag tells roslaunch to run a node. Here are what the node tags attributes mean:

  • pkg: the package your node is in
  • type attribute says what the executable name is (for C++, for Python this is the filename so you would put the file extension)
  • name: this is what you want ROS Master to call your node. This is useful for giving nodes meaningful names and using multiple instances of the same node in the same namespace.

You can also configure nodes via parameters and include launch files within launch files (within launch files...) to create a very complex system. In fact, some ROS packages can be composed of nothing but launch files from other packages!

Launch files are one of the many powerful features of ROS because they make it very easy to configure your system and they promote extensibility and resuse. There are many more features of launch files and I recommend that you read through the wiki to get a better understanding of them.

This wiki entry for roslaunch does a good job of explaining the roslaunch XML format and the book A Gentle Introduction to ROS has a chapter on how to use launch files as well.


Edit:

TL;DR:

catkin is used to compile the code into executables (or, for Python you chmod +x it) and then you tell roslaunch what executable to execute with the node tag and its attributes.

Longer explanation:

For the "logical" part: roslaunch will run exectuables from a package. It knows what executable you want to run through the node tag's type attribute. You put the executable's name as the value for type and roslaunch knows that you want to run an executable with the same name (from the package that you specified with the pkg attribute). This can be from C++, Python, or whatever supported language was used to write the node.

The code in the src folder (or wherever it is located) is not going to be executed by roslaunch, only executables can be run.

edit flag offensive delete link more

Comments

Well, thanks for the whole explanation. But the thing I don't understand it's what I said "logical" part. Most of the packages included in ROS have .cpp/.h/.py files, there you have a lot of code and I thought the launch files are executing those .cpp/.h/.py files.

julimen5 gravatar image julimen5  ( 2017-09-14 16:18:33 -0500 )edit

Now I get it. I didn't know about the "type". i really appreciate your help!!

julimen5 gravatar image julimen5  ( 2017-09-14 17:13:38 -0500 )edit

No problem, glad to help.

jayess gravatar image jayess  ( 2017-09-14 17:14:59 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-09-13 16:31:28 -0500

Seen: 1,250 times

Last updated: Sep 14 '17