ROS Workspace

Create and manage a ROS workspaces

Content Outline

    Names in ROS 2


    Names can be:

    • absolute path (begins with /): /global/name
    • relative path: relative/name
    • privately (begins with ~): ~private/name
    • namespace: namespace prefix to apply to entities associated with the node (node name, topics, etc). /namespace/name, this is very useful to group nodes and topics by “groups” in this case the “group” is the prefix namespace.

    Names in ROS

    External resources:

    The Workspace


    The concept of workspace is ROS VERSION independent, with this I mean that it doesn’t matter if you are using ROS 1 or ROS 2, both use the workspace concept.

    ROS workspace

    A workspace is a directory containing ROS packages.

    But, what is a ROS package?… more about it later (see ROS Packages ), for now just think about a box/package with some code, configs and more in it, trust me.

    The workspace contains:

    • Packages contains:
      • Executables
      • Libraries
      • Message definitions
      • Config files and more
    • Meta-Packages (ROS 1 concept): a package containing other packages

    Underlay

    Underlay workspace

    It contains the necessary dependencies of all the packages required by the 'overlay'.

    Underlay workspace.

    Let’s explore our underlay workspace: /opt/ros/humble/

    Important:

    Keep in mind that an underlay does not necessarily have to be the main ROS 2 installation.

    Overlay

    Overlay workspace

    Extends the underlay. (You will normally work here).

    Note, that for some reason unknown to me, the terms “underlay” and “overlay” are not frequently used in the ROS community. The vast majority of people when they refer to workspace it is usually the overlay workspace.

    Overlay workspace.

    Create a Workspace


    Create a overlay workspace is simple as creating a folder using the mkdir bash command. Just keep in mind that this folder MUST contain a src folder inside. Inside the src folder your packages will live.

    create a workspace
    mkdir -p ~/ros2_ws/src cd ~/ros2_ws

    Building a Workspace


    The build tool in ROS 2 is called colcon (collective construction). colcon is an iteration on the ROS build tools catkin_make, catkin_make_isolated, catkin_tools and ament_tools. colcon compile, test and install packages for you. colcon internally uses build systems depending on the type of package to compile or test, CMake for C++ packages and setuptools for python.

    Open a new terminal and try to run the following commands:

    build workspace
    cd ~/ros2_ws colcon build --symlink-install

    Failure? Why? hint: the ament_cmake is a ROS package that is currently not available.

    The option --symlink-install creates a symlink to their original locations instead of copying.

    This will create a three folders:

    • build
    • install
    • log

    Important:

    You should always run the build command from the ROOT of the workspace

    External resources:

    Source a Workspace (Activate it)


    Workspace activation (source) is accumulative.

    Don’t forget to source your underlay in EVERY terminal you open.

    source underlay
    source /opt/ros/humble/setup.bash
    source overlay
    source install/local_setup.bash

    External reference on sourcing here

    What is the diference on setup.bash in the underlay an local_setup.bash in the overlay?

    • setup.bash in the underlay under /opt/ros/<DISTO>/setup.bash enables all the packages in the underlay.
    • local_setup.bash in the overlay under (usually) ~/<YOUR WORKSPACE>/install/local_setup.bash enables the ONLY the current workspace.
    • setup.bash in the overlay under ~/<YOUR WORKSPACE>/install/setup.bash enables the current workspace as well as the underlay it was created in.

    Important:

    You may need to re-source the workspace after adding new packages

    Sourcing Tips


    If you want to automate the process of sourcing the underlaying workspace you can use the power of bash in linux:

    echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc

    Installing Dependencies


    Managing dependencies:

    install dependencies with rosdep
    rosdep install -i --from-path src --rosdistro humble -y