A ROS package is the modular unit used to organize ROS software. At minimum, it has package metadata in package.xml and a build file such as setup.py or CMakeLists.txt. It can also hold source code, robot descriptions, configuration, message definitions, and other data. Packages let a robot application be split into reusable, independently built parts rather than one large program. section 4.3 section 4.8
Packages live in a workspace: a directory arranged for storing, building, and running several packages together. Source packages go in src; colcon builds them and manages dependencies, creating build, install, and log directories. After building, source the workspace installation so ROS tools can find its packages and executables. section 4.3
A package commonly provides these pieces:
- Metadata and declared dependencies, allowing ROS tools and builds to identify what the package needs. section 4.3 section 4.7
- Build instructions for Python or CMake-based packages. section 4.3
- One or more ROS node executables, which use client libraries to communicate through the ROS middleware. section 4.4
- Interfaces in dedicated packages when defining custom messages; custom message packages use ament_cmake. section 4.7
Create, build, and expose a Python package
Create my_ros_ex4 under a workspace src directory with ament_python and a geometry_msgs dependency. Run colcon build from the workspace root, source install/setup.sh, then use ros2 pkg list to confirm that ROS discovers the new package. The same workflow supports packages containing publisher and subscriber executables. section 4.7 section 4.3 section 4.4
/home/USERNAME/rfp_ws
├── build
│ ├── COLCON_IGNORE
│ └── rfp_min_pub
├── install
│ ├── COLCON_IGNORE
│ ├── _local_setup_util_sh.py
│ ├── local_setup.sh
│ ├── rfp_min_pub
│ └── setup.sh
├── log
│ ├── COLCON_IGNORE
│ ├── build_2024-01-01_12-34-56
│ ├── latest -> latest_build
│ └── latest_build -> build_2024-01-01_12-34-56
└── src
└── rfp_min_pub
The workspace tree makes the package lifecycle visible: source packages remain under src, while colcon generates separate build, install, and log outputs. section 4.3
