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 herebuild/— colcon build artifacts (auto-generated)install/— final installed files; sourced to activate packageslog/— build logs
Steps¶
1. Source ROS 2
Do this in every new terminal, or add to ~/.bashrc:
source /opt/ros/humble/setup.bash2. Create the workspace
mkdir -p ~/ROBOT/src
cd ~/ROBOT3. Create the package
cd ~/ROBOT/src
ros2 pkg create robot_pkg --build-type ament_python --dependencies rclpyThis creates the folder structure:
robot_pkg/
├── package.xml
├── setup.cfg
├── setup.py
└── robot_pkg/
└── __init__.py4. Build the workspace
cd ~/ROBOT
colcon build5. Source the workspace
Run this after every build, in every terminal that needs the package:
source ~/ROBOT/install/setup.bash6. Verify
ros2 pkg list | grep robot_pkgExpected output:
robot_pkgExpected Terminal Output¶
Starting >>> robot_pkg
Finished <<< robot_pkg [2.34s]
Summary: 1 package finished [2.47s]Troubleshooting¶
| Problem | Solution |
|---|---|
ros2: command not found | Run source /opt/ros/humble/setup.bash |
colcon: command not found | Run sudo apt install python3-colcon-common-extensions |
| Package not found after build | Source the install: source ~/ROBOT/install/setup.bash |