liveBook · Manning

ROS package

As explained in Robotics for Programmers

A ROS package is a modular software unit containing metadata, build instructions, and optionally source code, robot descriptions, configuration, or other data.

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

How Robotics for Programmers covers it

How deep it goes
Defines required files and workspace workflow, then practices creation, dependencies, building, sourcing, and discovery.
Examples
Uses Python packages, geometry_msgs dependencies, publisher/subscriber executables, and a FooBar custom-message package.
What it assumes
Assumes a working ROS installation and environment setup before workspace and package commands.
What you can do after
Operate/configure it with colcon and ros2 CLI commands to create, build, source, verify, and run packages.
How it connects
Connects packages with ROS workspaces, colcon, ROS nodes, client libraries, topics, and custom message types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Robotics for Programmers. The section links point to the parts of the book it draws on.