Workspace and Development Environment

ROS 2 Workspaces

A ROS 2 workspace is a directory that contains your source packages and the build artifacts generated by colcon. A typical workspace layout is:

ros2_ws/
  src/
    my_package/
    another_package/
  build/
  install/
  log/

Key Directories

  • src/

    • Contains the source code of your ROS 2 packages.

    • This is where you clone or create new packages.

  • build/

    • Temporary build files generated by colcon build.

    • You rarely edit files here directly.

  • install/

    • Contains the final, installable artifacts and environment setup files.

    • After a successful build, you source install/setup.bash to use your packages.

The colcon Build Tool

  • colcon is the build tool used by ROS 2 workspaces.

  • Typical workflow:

    cd ~/ros2_ws
    colcon build
    
  • After building, you must source the workspace:

    source ~/ros2_ws/install/setup.bash
    

    This step extends your environment so that ROS 2 can find your new packages.

Overlaying Workspaces

ROS 2 supports an emph{overlay} mechanism:

  • The base installation (for example, /opt/ros/humble) is your emph{underlay}.

  • Your development workspace emph{overlays} that underlay.

  • When you source:

    source /opt/ros/humble/setup.bash
    source ~/ros2_ws/install/setup.bash
    

    ROS 2 searches for packages in the overlay first, then falls back to the underlay.

This allows you to:

  • Override a package from the system installation with your own fork.

  • Keep system packages intact while experimenting in your workspace.