CodeTheRobot

ROS 2 Lyrical lab 02 ยท 35 min

Create the robotics workspace

Build a clean colcon overlay at ~/robot_ws and understand each generated directory.

Practice this lab in your browser: Prove the overlay wins

Understand before building

How this part of ROS 2 works

A colcon workspace separates source files from generated build, install, and log data. Only src is authored by you.

The installed ROS distribution is the underlay; your workspace is an overlay. Sourcing the overlay makes your newly built packages discoverable.

Before you start

  • ROS 2 Lyrical sourced
  • colcon installed

Files you will touch

  • ~/robot_ws/src/
  • ~/robot_ws/build/
  • ~/robot_ws/install/
  • ~/robot_ws/log/

Step 1

Set up

source /opt/ros/lyrical/setup.bash
mkdir -p ~/robot_ws/src
cd ~/robot_ws
colcon build --symlink-install

Step 2

Create the file

# Source the overlay after every successful build.
source ~/robot_ws/install/setup.bash
printenv AMENT_PREFIX_PATH

What each part does

  1. 1.mkdir creates the conventional source directory without failing if it exists.
  2. 2.colcon builds discovered packages and creates setup files; sourcing install/setup.bash activates the overlay.

Step 3

Build, run and inspect

cd ~/robot_ws
colcon list
colcon build --symlink-install
source install/setup.bash

Proof that it works

  • The build finishes without failed packages
  • install/setup.bash exists
  • The workspace path appears before /opt/ros/lyrical in AMENT_PREFIX_PATH

Recovery notes

  • Remove build, install and log only when a clean rebuild is necessary; never remove src.
  • Build one package with --packages-select PACKAGE_NAME to isolate errors.
ROS 2 colcon tutorial