Atlas Robotics
ROS2 BasicsBasic

What is a package in ROS2?

Atlasbot · 16/8/2026 · 10 min read

What is a package in ROS2?
The structure within a ROS2 package

Everything in ROS2 — a motor control node, a launch file that launches the whole system, a Nav2 — set of configuration files must be inside a package. This is the smallest packaging unit that colcon build understands and knows how to compile/install.

Key concepts

A minimal ROS2 package needs an required file: package.xml— the manifest describing the name, version, author, and most importantly the list of other packages to which it depends (dependencies). With this declaration, when building the entire workspace, colcon knows which packages to build first, and which packages to build later in the correct order of dependency.

Two package types: ament_cmake and ament_python

  • ament_python— for a package in Python, requires the inclusion of a setup.py/setup.cfg file
  • ament_cmake — for C++ written packages (or C++/Python merging), requires the addition of a CMakeLists.txt file describing the compilation

The internal subdirectory structure usually follows the general convention of either type: launch/ (launch file), config/ (YAML parameter file), msg//srv//action/ (definition of self - declared data type, if any), and real-world source code (src/ for C++, the same package name directory for Python).

Summarized:package.xml is the "identity" of the package — Properly declaring the dependency here helps colcon build to take care of the build order itself, without you having to remember which package to build first.

How it works

Create a new Python package in the workspace using an existing tool, without manually typing each file:

cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python my_robot_package

The above command generates the standard structure:

my_robot_package/
├── package.xml           ← name and dependency declarations
├── setup.py              ← installation instructions (Python)
├── setup.cfg
├── resource/my_robot_package
└── my_robot_package/     ← directory containing actual Python code
    └── __init__.py

After adding code node to directory with package name, declare executable in setup.py (entry_points), then rebuild from the workspace root directory (colcon build) — the new package can be run immediately with ' ros2 run my_robot_package <node_name>.

Technical details

Parameters

The package naming convention follows REP-144 (the official ROS standard) and the current package.xml format:

RulesRequest
Allow charactersLowercase, number, underscore (_) — without uppercase/dashes
Do not start with numbersE.g. robot_driver valid, 2wd_driver invalid
Format package.xmlFormat 3 (currently) — supports separate <depend>, <build_depend>, <exec_depend>, <test_depend> declarations

Differentiating dependency types in package.xml: <build_depend> needs only at compile time, <exec_depend> requires only at runtime, <depend> needs for both — to properly declare types reduces excess dependency when packaging distribution packages.

Practical applications

Real-world robotics projects rarely package entire code into a giant package — the common practice is to separate by responsibility: 1 package _msgs contains only a custom message/service definition (less changes, more dependencies), 1 package _driver contains hardware communication code, 1 package _navigation contains private navigation logic. Such splittings helped colcon build --packages-select only build the correct part of the fix (much faster than reconstructing the whole), and allowed different teams in the team to develop in parallel less clashingly.

Practical example

$ ros2 pkg list | grep my_robot
Output:
my_robot_driver
my_robot_msgs
my_robot_navigation
$ ros2 pkg xml my_robot_driver
Output (short):
<?xml version="1.0"?>
<package format="3">
  <name>my_robot_driver</name>
  <version>0.1.0</version>
  <depend>rclcpp</depend>
  <depend>my_robot_msgs</depend>
</package>

ros2 pkg list lists every package that ROS2 is currently "visible" to (with the correct source workspace) — the first tool to check if a new build package is actually identified before a code error is suspected.

Common mistakes

  • Compliant package name— uses uppercase or dashes (e.g., MyRobot-Driver) which causes ament/colcon to report inconsistent errors or operations — to always use snake case (normal + underscore).
  • The dependency declaration in package.xml— code is still buildable if the dependency is installed on the dev, but when packed/developed on another host (or using rosdep install for automatic installation) is missing, making runtime errors difficult to diagnose because the build error is still "green".
  • Mixing the ament_cmake and ament_python conventions in the same package— the pure Python package does not need CMakeLists.txt, the pure C++ package does not need setup.py— mistakenly add files of the other type causing a confusing build error.
  • forgets build + source after adding new package to workspace—ros2 pkg list no new package is seen because colcon build and source install/setup.bash have not been re-installed, misleadingly the package has a structural error.

Conclusion

The package is the fundamental packaging unit of everything in ROS2 — mastered package.xml and proper dependency declaration is a continuous skill to use when expanding a robot project into multiple organized small packages. The next article in the column is about the Node — smallest executable unit inside a package, where the robot's true logic runs.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

What is a package in ROS2? — Atlas Robotics