Understanding ROS Packages: A Comprehensive Guide

ROS (Robot Operating System) packages are the fundamental building blocks of ROS-based robotics software. This guide will explain what ROS packages are, their purpose, structure, and how to work with them effectively.

What is a ROS Package and Why Do We Need It?

1. Minimal Distribution Unit

2. Dependency and Build Manager

3. Namespace Management

4. Distribution and Installation

What’s Inside a Typical Package?

The following example shows a ROS 1 (catkin) structure. ROS 2 (ament) structure is similar, with main differences in package.xml format being stricter and build instructions written differently in CMakeLists.txt.

my_robot_package/
├── CMakeLists.txt          # Build script: compilation options, dependencies, target executables
├── package.xml             # Metadata: package name, version, dependencies, license, maintainer
├── include/                # Header files for other packages to #include
│   └── my_robot_package/
├── src/                    # C/C++ source code, compiled into executables or libraries
│   └── main.cpp
├── scripts/                # Python / Bash scripts, requires chmod +x
│   └── talker.py
├── launch/                 # *.launch or *.py (ROS2) files, one-click startup of multiple nodes
│   └── demo.launch
├── config/                 # YAML or .rviz / .yaml parameter configurations
│   └── joystick.yaml
├── msg/                    # Custom messages *.msg
│   └── WheelVel.msg
├── srv/                    # Custom services *.srv
│   └── SetSpeed.srv
├── action/                 # Custom actions *.action
│   └── Navigate.action
├── urdf/                   # Robot models *.urdf, *.xacro
│   └── my_robot.urdf.xacro
├── rviz/                   # RViz configurations, Marker resources
├── meshes/                 # STL/DAE visual and collision models
└── README.md               # Documentation

Directory/File Responsibilities

1. package.xml

2. CMakeLists.txt

3. src/ and include/

4. scripts/

5. launch/

6. msg/srv/action

7. config/

8. urdf/, meshes/, rviz/

ROS 1 vs ROS 2 Package Differences

1. Build System

2. Launch Files

3. Security and Cross-Platform

Common Development Workflow

1. Create Package

# ROS1
catkin_create_pkg my_package roscpp rospy std_msgs

# ROS2
ros2 pkg create --build-type ament_cmake my_package --dependencies rclcpp std_msgs

2. Write Code → Compile

catkin_make         # or colcon build
source devel/setup.bash

3. Run

rosrun my_package talker
roslaunch my_package demo.launch

Best Practices

Package Naming

Dependency Management

Documentation

Version Control

Summary

ROS Packages provide a “minimal reusable unit” packaging method, making robot software modular like LEGO blocks. A package typically contains: metadata (package.xml), build scripts (CMakeLists.txt), source code, scripts, launch files, parameters, models, and custom messages. Understanding package structure and dependency declaration is the foundation for ROS development and distribution.


ROS packages are the cornerstone of modular robotics development, enabling code reuse, easy distribution, and systematic dependency management in the robotics ecosystem.