Creating A Workspace

Concept

A workspace is a folder that contains all your ROS 2 packages and build artifacts. A package is a self-contained module inside a workspace — it holds your nodes, launch files, and configuration.

  • src/ — your source packages go here
  • build/ — colcon build artifacts (auto-generated)
  • install/ — final installed files; sourced to activate packages
  • log/ — build logs

Steps

1. Source ROS 2

Do this in every new terminal, or add to ~/.bashrc:

source /opt/ros/humble/setup.bash

2. Create the workspace

mkdir -p ~/ROBOT/src
cd ~/ROBOT

3. Create the package

cd ~/ROBOT/src
ros2 pkg create robot_pkg --build-type ament_python --dependencies rclpy

This creates the folder structure:

robot_pkg/
├── package.xml
├── setup.cfg
├── setup.py
└── robot_pkg/
    └── __init__.py

4. Build the workspace

cd ~/ROBOT
colcon build

5. Source the workspace

Run this after every build, in every terminal that needs the package:

source ~/ROBOT/install/setup.bash

6. Verify

ros2 pkg list | grep robot_pkg

Expected output:

robot_pkg

Expected Terminal Output

Starting >>> robot_pkg
Finished <<< robot_pkg [2.34s]

Summary: 1 package finished [2.47s]

Troubleshooting

ProblemSolution
ros2: command not foundRun source /opt/ros/humble/setup.bash
colcon: command not foundRun sudo apt install python3-colcon-common-extensions
Package not found after buildSource the install: source ~/ROBOT/install/setup.bash