How ros2/examples works
This repository is a collection of ROS 2 example packages, not a single application. The architectural unit is the package: each example lives in its own ROS package with its own manifest, build config, and entry points, and all of them communicate through the ROS 2 runtime and middleware rather than through internal library calls.
1. Top-level split by language and purpose
- rclcpp/ contains C++ examples.
- rclpy/ contains Python examples.
- launch_testing/ contains examples of ROS 2 launch-based system testing.
- The repo is organized as a tutorial/reference suite for ROS 2 concepts, with no central service or shared runtime state beyond the ROS graph.
2. Package boundary model
- Most subdirectories under rclcpp/ and rclpy/ are standalone packages with their own package.xml.
- Python examples additionally have setup.py, setup.cfg, and resource/ markers, showing they install as importable Python packages and executable console scripts.
- C++ examples have CMakeLists.txt, indicating standard ROS 2/ament C++ builds.
- This means each example can be built, installed, and run independently.
3. Primary communication pattern: topics
- The topics/minimal_publisher and topics/minimal_subscriber packages in both languages are the core pub/sub examples.
- Data flows from publishers into the ROS middleware and then out to subscribers via topic names and message types.
- These packages demonstrate variants such as lambda callbacks, member functions, type adapters, QoS-related behavior, and composition-aware versus standalone nodes.
- rclpy/topics/pointcloud_publisher is a more concrete topic example publishing a richer sensor-style message rather than a trivial string.
4. Request/response boundary: services
- services/minimal_service and services/minimal_client in both languages show the synchronous and asynchronous service interaction model.
- The server owns the request-handling boundary; the client issues requests and receives responses through the ROS service transport.
- Several Python variants show different callback styles and asynchronous usage, while the C++ examples show minimal and async client patterns.
5. Long-running goal-based interaction: actions
- actions/minimal_action_server and actions/minimal_action_client demonstrate the action protocol.
- The data flow is more complex than services: a goal is accepted, progress feedback may stream back, and the client can cancel or wait for completion.
- Variants cover single-goal behavior, queued goals, deferred execution, feedback, and composability differences.
6. Execution and scheduling layer
- executors/ in both languages focuses on how callbacks are scheduled and driven.
- Python examples include custom callback groups and custom executors, showing the boundary between node logic and callback dispatch.
- C++ examples include a multithreaded executor and a callback-group-based executor sample (cbg_executor), emphasizing concurrency and coordination across callbacks.
7. Low-level event handling with wait sets
- rclcpp/wait_set and the wait-set-related examples in rclcpp/topics/minimal_subscriber expose a lower-level reactive model than standard executors.
- These examples show nodes waiting on specific combinations of topics, timers, and events, including static and random-order behavior.
- Architecturally, this is the “manual event loop” layer of the repo.
8. Timers and periodic callbacks
- rclcpp/timers/minimal_timer demonstrates periodic work driven by the ROS timer subsystem.
- The timer callback is the source of activity, and any publishing or state update happens on that schedule rather than in response to incoming messages.
9. Node composition and in-process reuse
- rclcpp/composition/minimal_composition shows how nodes can be built as reusable components and loaded together.
- It includes publisher/subscriber node classes plus standalone and composed entry points.
- This package defines the boundary between node implementation and deployment shape: the same node logic can run as separate processes or as composed components.
10. Launch testing as system-level verification
- launch_testing/launch_testing_examples is a separate test-oriented subsystem.
- It uses ROS 2 launch descriptions and runtime assertions to validate behavior of started nodes, parameter setting, message flow, and rosbag recording.
- This is the integration-test layer of the repo: it exercises whole-node behavior rather than unit-level library logic.
11. Cross-cutting ROS 2 infrastructure
- All examples sit on top of ROS 2 concepts: nodes, publishers/subscribers, services, actions, executors, callback groups, timers, and launch.
- The runtime boundary is the ROS graph and middleware transport, so diagramming should show packages as independent nodes/processes connected through ROS topics, services, actions, or test launch orchestration.
12. Repo-wide packaging and quality tooling
- Many packages include CHANGELOG.rst, README.md, and test directories.
- Python packages commonly include lint/style tests such as flake8, pep257, xmllint, and copyright checks.
- These are supporting concerns, not runtime subsystems, but they reinforce that each example is maintained as a distributable ROS package.
In short: this repo is a catalog of small, self-contained ROS 2 packages demonstrating specific communication and execution patterns, with the main architectural boundaries defined by language (C++ vs Python), interaction model (topic/service/action/timer/wait set), and deployment shape (standalone vs composed vs launch-tested).
Main entry points: launch_testing_examples Launch tests · topics/minimal_publisher Topic pub · topics/minimal_publisher Topic pub · minimal_service Service srv
Components 20
rclcpp
C++ ROS 2 example packages
- Topic pub · C++ minimal publisher variants
rclcpp/topics/minimal_publisher - Topic sub · C++ minimal subscriber variants plus wait-set-driven subscriber samples
rclcpp/topics/minimal_subscriber - Service srv · C++ minimal service server variants
rclcpp/services/minimal_service - Service cli · C++ minimal and async service client variants
rclcpp/services/minimal_client - Action srv · C++ action server variants
rclcpp/actions/minimal_action_server - Action cli · C++ action client variants
rclcpp/actions/minimal_action_client - Executors · C++ executor and callback-group scheduling examples
rclcpp/executors/cbg_executor - Wait set · C++ manual event-loop and wait-set examples
rclcpp/wait_set - Timers · C++ periodic timer examples
rclcpp/timers/minimal_timer - Composition · C++ component and standalone deployment examples
rclcpp/composition/minimal_composition
rclpy
Python ROS 2 example packages
- Topic pub · Python minimal publisher variants and pointcloud publisher
rclpy/topics/minimal_publisher - Topic sub · Python minimal subscriber variants
rclpy/topics/minimal_subscriber - Service srv · Python minimal service server variants
rclpy/services/minimal_service - Service cli · Python synchronous and asynchronous service clients
rclpy/services/minimal_client - Action srv · Python action server variants
rclpy/actions/minimal_action_server - Action cli · Python action client variants
rclpy/actions/minimal_action_client - Executors · Python callback-group and custom executor examples
rclpy/executors - Guard cond. · Python guard condition trigger example
rclpy/guard_conditions
launch_testing
Launch-based system testing examples
- Launch tests · Launch-based integration and system test examples
launch_testing/launch_testing_examples
Other components
- ROS 2 runtime · Shared ROS graph, message transport, and callback scheduling boundary for all examples
Connections 23
- Topic pub → ROS 2 runtime: publishes topics · C++ publishers send messages into the ROS graph
- ROS 2 runtime → Topic sub: delivers topics · Subscribers receive messages from the ROS graph
- Topic pub → ROS 2 runtime: publishes topics · Python publishers send messages into the ROS graph
- ROS 2 runtime → Topic sub: delivers topics · Subscribers receive messages from the ROS graph
- Service cli → ROS 2 runtime: calls service · C++ clients issue service requests through ROS transport
- ROS 2 runtime → Service srv: handles service · Servers receive requests and return responses
- Service cli → ROS 2 runtime: calls service · Python clients issue service requests through ROS transport
- ROS 2 runtime → Service srv: handles service · Servers receive requests and return responses
- Action cli → ROS 2 runtime: sends goal · Action clients submit goals and receive feedback/results
- ROS 2 runtime → Action srv: executes goal · Action servers accept goals and manage progress
- Action cli → ROS 2 runtime: sends goal · Action clients submit goals and receive feedback/results
- ROS 2 runtime → Action srv: executes goal · Action servers accept goals and manage progress
- Executors → ROS 2 runtime: schedules callbacks · Executor and callback-group behavior sits above ROS entities
- Executors → ROS 2 runtime: schedules callbacks · Custom executors and callback groups drive callback dispatch
- Wait set → ROS 2 runtime: waits on events · Manual wait-set loops react to specific ROS events
- Timers → ROS 2 runtime: triggers timers · Periodic callbacks drive activity through the ROS timer subsystem
- Composition → ROS 2 runtime: loads components · Composable nodes can run in-process or standalone
- Guard cond. → ROS 2 runtime: triggers guard · Guard conditions integrate with ROS event handling
- Launch tests → ROS 2 runtime: launches tests · Launch descriptions start nodes and assert runtime behavior
- Launch tests → Topic pub: tests · Launch tests exercise node behavior
- Launch tests → Topic pub: tests · Launch tests exercise node behavior
- Launch tests → Service srv: tests · Launch tests exercise node behavior
- Launch tests → Service srv: tests · Launch tests exercise node behavior