CodeTheRobot

ROS 2 Lyrical Luth · Lesson 03 of 86

Workspace structure: src, build, install and log

What each workspace folder holds, underlay and overlay, and what to commit.

Estimated time · 30–45 min

Learning goals

What you will understand

  • Explain workspace structure: src, build, install and log in your own words
  • Use it in a small robotics example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

A ROS 2 workspace is a folder that holds packages and the results of building them. src/ contains your source packages (this is the only folder you edit and commit); build/ holds intermediate files; install/ holds the finished, runnable result; log/ holds build logs.

The installed ROS distribution is the underlay. When you source a workspace's install/setup.bash it becomes an overlay on top, so your packages are found first. Always source the underlay before building, and never commit build/, install/ or log/.

Guided lesson

Work through these steps

  1. 1.

    Source the ROS 2 Lyrical environment in a fresh terminal.

  2. 2.

    Read the workspace structure: src, build, install and log example and identify what each line does.

  3. 3.

    Build only the affected package, source the workspace overlay, and run the example.

  4. 4.

    Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.

Worked example

Read it before you run it

mkdir -p ~/robot_ws/src
# Create the workspace with its src folder.
cd ~/robot_ws
# Work from the workspace root.
ls
# Before building only src exists.
colcon build
# Build every package under src (an empty workspace builds instantly).
ls
# Now build, install and log appear next to src.
source install/setup.bash
# Add this workspace as an overlay in the current terminal.
printf 'build/\ninstall/\nlog/\n' > .gitignore
# Keep generated folders out of version control.

What the example is doing

  1. 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
  2. 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
  3. 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.

Watch it run · Build and run

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

sourcecompilerprogramBUILD AND RUN

Demo for Workspace structure: src, build, install and log. Expected result: src build install log

Practice code

Now type it yourself

Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.

# Create and build an empty workspace, then list it
mkdir -p ~/robot_ws/src
cd ~/robot_ws
# TODO: build the workspace with colcon
ls

Expected output

src build install log
Stuck? Show the full solution (try it yourself first)
# Create and build an empty workspace, then list it
mkdir -p ~/robot_ws/src
cd ~/robot_ws
colcon build
ls

Expected result

How you know it worked

  • ROS_DISTRO is lyrical in every terminal used for the exercise.
  • The complete package from the exercise builds and the expected graph entity appears in a second terminal.

Practical exercise

Apply the lesson

Create ~/robot_ws/src, build it, list the four folders, and write one sentence explaining what each contains. Then start a new terminal and prove your overlay is not active until you source it.

Before you continue

  • ROS_DISTRO reports lyrical in every terminal you used
  • The example builds and runs without errors
  • You checked the result with a ros2 command, RViz2 or a test, not just by reading the code

If something goes wrong

ros2 cannot find a package or executable.

Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.

Nodes run but cannot discover each other.

Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.