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

ROS File Structure

< Back to ROS Beginner tutorials
ROS Workspace
Creating a ROS Workspace
File Structure
Creating a Package
Package tools in ROS
Components of ROS

ROS Workspace

A ROS Workspace is like the home directory for all the ROS related work on your system. It's nothing but a special folder which stores all the executable items and everything you create in ROS. So it's like a parent directory for ROS development. Usually people have only one workspace, but you could have many. Essentially, if you have a project that requires a lot of things, it's generally a good idea to create a workspace.

I'd prefer to create a folder in your home folder that contains all the ROS workspaces, so the entire ROS development is at one place. But actually, you can create a workspace anywhere you have permissions.

Creating a ROS Workspace

To create a ROS workspace, do the following:

  1. Open a terminal (Ctrl + Alt + T)
  2. Setup the folders required for the workspace. Type in the following commands into the terminal and press Enter after every command to execute it
    • cd ~
      • Change to the home directory
    • mkdir ROS_workspaces
      • Create a directory where you'll store all the workspaces in. It could bear any name, need not be "ROS_workspaces"
    • cd ROS_workspaces
      • Navigate into it
    • mkdir -p ros_ws/src/
      • Make the workspace directory. Our workspace is ros_ws. You could name it anything, needn't be ros_ws. This also creates a folder named src inside the workspace directory. This is the folder where you'll put all the development stuff into.
    • cd ros_ws/src/
      • Navigate into the src folder in the workspace directory. You might as well open it in Files just to see how things go now. It must be empty.
  3. Initialize the workspace so that it contains all the essential files which a workspace must have. Type in the following commands into the terminal and press Enter after every command to execute it
    • cd ~/ROS_workspaces/ros_ws/src/
      • This will get you into the src folder of the workspace. Keep in mind that the workspace name is "ros_ws" and the "ROS_workspaces" folder is a folder in which we'll be storing all the ROS workspaces in our system.
    • catkin_init_workspace
      • This initializes a link (a reference) to the workspace, saying ROS that this is where this workspace is located on the system. You must get an output telling you that a symlink has been created. If you run the command ls -la, you'll observe that a new file called CMakrLists.txt has been created (you could verify the same using Files)
    • cd ../
      • Navigate back to the workspace folder. Observe that for now, there's only the src folder inside it.
    • catkin_make
      • This builds the workspace. Basically, it's like making applications for the code in src folder. You could inspect the contents using Files or using the command ls -la */. We'll explore more about them later, but notice the "setup.bash" in the devel folder.
  4. Now that you have created and initialized the workspace, you have to tell ROS that 'here is my workspace'. Type in the following commands into the terminal and press Enter after every command to execute it
    • source ~/ROS_workspaces/ros_ws/devel/setup.bash
      • Whenever this command is run, ROS adds your workspace to it's path for packages. You could verify this by echo $ROS_PACKAGE_PATH and the output will also have your workspace source directory.
      • I'd suggest that you append this line in your "~/.bashrc" file, in the section which you've made for ROS. Put it after the main ROS source line. At a time, only one workspace must be sourced, generally (to avoid conflicts). It's a good idea to put all the workspace sourcing commands in the "~/.bashrc" file, comment everything but the one you want to use. At the end, the ROS section of your "~/.bashrc" file must look something like what's shown below

ROS section of "~/.bashrc" file

  • Notice how the main ROS sourcing comes first, then the workspaces
  • Only one workspace is uncommented and others are commented out
  • I have other workspaces as well, if you come about having multiple workspaces, this is a neat way of organizing them.
  • You could comment out everything in this section if you don't want to use ROS in the terminal sessions

This time onward, whenever you want to do anything ROS on a terminal, make sure that you have the correct workspace setup file sourced (either in the "~/.bashrc" file or do it manually every time).

That's it, you've created the parent directory and basic files for development in ROS. Let's know a little about the way we organize files in ROS

File Structure

Here's an image showing the basic structure in which ROS stores files. There is much more to it which we'll cover later, but for now there are a few things that we must note

  • A package is basically a group of things designed to serve one (and only one) purpose. This is how ROS maintains isolation, you develop different aspects in different packages and then you can later merge them all into a single package (called as a metapackage, but we'll learn more about that later). Let's inspect the contents of a package
    • All "CMakeLists.txt" files are for the cmake tool, which is invoked by the catkin tool when we call `catkin_make` in the workspace directory. More on this here.
    • A "Package.xml" file is basically a manifesto, list of things that the package needs to function, what is it dependent on, so on and so forth. More on this here.
    • The src folder is for source files, written in C++ and the scripts folder is for python scripts. The include folder is usually to contain C++ dependencies (like the extra header files that are included in code).
    • All packages must reside under the src folder in the workspace.
  • The devel folder in the workspace is for storing executables and compiled programs. It also contains the sourcing scripts for recognizing the workspace.
  • The build folder is mainly for building the workspace, it's for the cmake tool and everything here is handled by a special tool catkin. So we don't need to care much about it further.

ROS File Structure

Now that we've seen how the files are organized, let's start by making our first package in the workspace that we just created.

Creating a Package

  1. Open a terminal (Ctrl + Alt + T)
  2. Navigate to the src folder of the workspace directory. Type in the following commands into the terminal and press Enter after every command to execute it
    • cd ~/ROS_workspaces/ros_ws/src/
      • Change present working directory
  3. Call the command to create a package, catkin_create_pkg and pass it the desired parameters. Type in the following commands into the terminal and press Enter after every command to execute it
    • catkin_create_pkg intro_pkg1 std_msgs roscpp rospy
      • The name of our package is "intro_pkg1". The names that follow are dependencies (which are other packages on which this package depends).
        • std_msgs is a package used for generating and receiving messages. We'll talk about this later, but for now, just think of it as an important package for communication, knowing different data types available, etc.
        • roscpp is a package required if you're developing the package in C++
        • rospy is a package required if you're developing the package in python. You can use both
      • The output of this command will tell you that some folders have been created and that the package has been successfully created. Take your time and see the contents using the Files application.
  4. Now that the package has been created and resides in the src folder of the workspace, it's time to build it. Type in the following commands into the terminal and press Enter after every command to execute it
    • cd ~/ROS_workspaces/ros_ws/
      • Go to the workspace directory
    • catkin_make
      • This calls the catkin tool that does the task of building the package. It makes all the executables and compiles everything as instructed in the "CMakeLists.txt" files.
      • This tool can only be invoked in the workspace directory, if invoked anywhere else, it might give an error or might lead to some erroneous results later in time. So best execute it in the workspace home directory.
      • The output must have a line telling that it's adding the sub-directory intro_pkg1.

Done ! You've successfully created your first package 🎊🎉

Package tools in ROS

Open a terminal and try out the commands in this font.

  • There are a few tools in ROS that are made to make navigating the ROS environment easier. Few of these are rosls and roscd, similar to (ls and cd in Ubuntu), but these help you to list package contents and change present working directory to a package.
  • Another useful tool is rospack. It helps us know about packages in detail. You could try rospack help to know everything about it.
  • To find packages, you could use "rospack find" command or the "catkin_find_pkg" command. A notable difference is given below (first cd ~/ROS_workspaces)
    • rospack find intro_pkg1
      • Gives the location of package from the root directory ('/')
    • catkin_find_pkg intro_pkg1
      • Gives the location of package from the current working directory

Now that we know ROS file structure and how to create a package, let's see what are the terminologies in ROS and what are the components in ROS

Components of ROS

Let's discuss in brief about some components in ROS. Just their name, what are they for, and what are the command line tools available for them. Check the spreadsheet next to know about all of them. We'll later learn them in detail, one by one

Basic components of ROS

We'll learn about each one of them, for now just see the output of the "Know more command" to get a gist of what the commands do and what they're used for. You can come back to this place anytime for reference anyways.

The workspace for these pages is stored on GitHub.

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