Prerequisites:

Basics:

A workspace is a directory containing ROS 2 packages (ROS 2 is version name and not two packages). Before using ROS 2, it’s necessary to source your ROS 2 installation workspace in the terminal you plan to work in. This makes ROS 2’s packages available for you to use in that terminal.

A ROS workspace is a directory with a particular structure. Commonly there is a src subdirectory. Inside that subdirectory is where the source code of ROS packages will be located. Typically the directory starts otherwise empty.

colcon does out of source builds. By default it will create the following directories as peers of the src directory:

Note: Compared to catkin there is no devel directory.

Create a workspace

First, create a directory (ros2_ws) to contain our workspace:


mkdir -p ~/ros2_ws/src
cd ~/ros2_ws

At this point the workspace contains a single empty directory src:


.
└── src

1 directory, 0 files

NOTE: Till here is what you need for TASK 0 to get started. Further if you want to explore more on ROS workspace, happy learning...


Add some sources

Let’s clone the examples repository into the src directory of the workspace: