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.
rosdep automatically installs system-level dependencies based on package.xml 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
build_depend, exec_depend, test_depend ament_cmake, pluginlib_export_plugin_description_file)find_package(catkin REQUIRED COMPONENTS roscpp std_msgs …) add_executable() / ament_target_dependencies() install() for rosrun/ros2 run and system package management#!/usr/bin/env python; ROS 2 emphasizes entry pointscatkin_make or colcon build <rosparam file= or ROS 2 param file= # ROS1
catkin_create_pkg my_package roscpp rospy std_msgs
# ROS2
ros2 pkg create --build-type ament_cmake my_package --dependencies rclcpp std_msgs
catkin_make # or colcon build
source devel/setup.bash
rosrun my_package talker
roslaunch my_package demo.launch
my_robot_package 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.