How ros2torial/ros2_basics works
1. Repository purpose
- This is a small ROS 2 training/demo workspace showing the same core patterns in C++ and Python: topic-based pub/sub, service-based request/response, custom interfaces, and launch orchestration.
2. Package layout is the main architectural boundary
- The repo is split into independent ROS 2 packages:
- cpp_topic, py_topic for topic examples
- cpp_service, py_service for service examples
- custom_interfaces for shared message/service definitions
- launch for multi-node startup composition
- nodejs_ui for a static UI artifact
- This separation is important because ROS 2 packages are the deployment/build units, not just folders.
3. Topic subsystem
- cpp_topic and py_topic each contain a publisher node and a subscriber node.
- The publisher examples generate a spiral-style stream of data/commands; the subscriber examples consume that stream.
- The same pattern is implemented twice, once in C++ and once in Python, which makes it useful as a language-comparison demo.
4. Service subsystem
- cpp_service and py_service each contain a service server and a service client.
- The flow is synchronous: the client sends a request, the server performs the computation/response, and the client receives the result.
- Again, the repo duplicates the pattern across C++ and Python to demonstrate ROS 2 service mechanics in both runtimes.
5. Shared interface contract
- custom_interfaces centralizes the application-level ROS contracts:
- msg/IOStatus.msg
- srv/OutputControl.srv
- This package is the cross-language boundary that lets C++ and Python nodes interoperate cleanly without duplicating type definitions.
- In architecture terms, it is the schema layer for the rest of the workspace.
6. Launch layer
- The launch/ folder contains turtlesim_two_turtle.py and parameter/remapping variants.
- These files represent the composition layer: they assemble multiple ROS nodes into one runtime, inject parameters, and optionally remap topics.
- The presence of “two turtle” launch files strongly suggests these demos are intended to run against a turtlesim-style simulation environment.
7. Runtime data flow
- The primary flows are:
- Topic flow: publisher node → ROS topic → subscriber node
- Service flow: client node → service request → server node → service response
- Launch flow: launch file → multiple nodes with parameters/remaps → coordinated demo
- Nothing here suggests a central backend; interaction is through the ROS graph.
8. Language/runtime split
- C++ nodes live under src/ with CMakeLists.txt and package.xml.
- Python nodes live in package modules with setup.py, setup.cfg, and package.xml.
- custom_interfaces uses CMake because ROS 2 must generate code for shared interfaces across languages.
- This mixed build model is a key architectural feature of ROS 2 workspaces.
9. NodeJS UI
- nodejs_ui/io_control.html is a standalone HTML asset, likely intended as a simple control/dashboard surface.
- There is no visible backend in the tree, so it should be treated as a UI experiment or integration artifact rather than a core runtime component.
10. What to show in an architecture diagram
- Draw custom_interfaces as the shared contract layer beneath both C++ and Python nodes.
- Show separate pub/sub and client/server pairs for each language.
- Show launch/ as the composition entrypoint that starts multiple nodes and applies parameters/remappings.
- If including the simulator, place turtlesim as an external runtime dependency that the launch files and nodes interact with through ROS topics/services.
11. Overall shape
- This repo is not a single application; it is a collection of ROS 2 examples organized around reusable communication patterns.
- The architectural emphasis is on inter-process messaging, shared interface definitions, and launch-time composition, with C++ and Python used side by side to demonstrate the same concepts.
Main entry points: custom_interfaces Interfaces · turtlesim_two_turtle.py Launch · cpp_topic C++ topic · cpp_topic_publisher_spiral.cpp Spiral pub
Components 18
C++ packages
ROS 2 examples implemented in C++.
- C++ topic · C++ pub/sub example package.
cpp_topic - Spiral pub · C++ topic publisher generating spiral-style output.
cpp_topic/src/cpp_topic_publisher_spiral.cpp - Spiral sub · C++ topic subscriber consuming the spiral stream.
cpp_topic/src/cpp_topic_subscriber_spiral.cpp - C++ service · C++ client/server example package.
cpp_service - Polar client · C++ client sending synchronous requests.
cpp_service/src/cpp_service_client_polar.cpp - Polar server · C++ service server handling requests and responses.
cpp_service/src/cpp_service_server_polar.cpp
Python packages
ROS 2 examples implemented in Python.
- Python topic · Python pub/sub example package.
py_topic - Spiral pub · Python topic publisher generating spiral-style output.
py_topic/py_topic/py_topic_publisher_spiral.py - Spiral sub · Python topic subscriber consuming the spiral stream.
py_topic/py_topic/py_topic_subscriber_spiral.py - Python service · Python client/server example package.
py_service - Polar client · Python client sending synchronous requests.
py_service/py_service/py_service_client_polar.py - Polar server · Python service server handling requests and responses.
py_service/py_service/py_service_server_polar.py
Shared layer
Interface definitions and composition assets used across examples.
- Interfaces · Shared message and service contracts for the workspace.
custom_interfaces - IOStatus · Shared status message definition.
custom_interfaces/msg/IOStatus.msg - OutputControl · Shared service definition for output control requests.
custom_interfaces/srv/OutputControl.srv - Launch · Launch files that assemble multi-node demos with parameters and remappings.
launch/turtlesim_two_turtle.py
UI artifact
Standalone browser-facing control surface.
- IO control · Standalone browser UI artifact for IO control or experimentation.
nodejs_ui/io_control.html
External runtime
Outside simulator/runtime dependency used by the demos.
- Turtlesim · External ROS 2 simulation environment targeted by the launch demos.
Connections 28
- Interfaces → IOStatus: defines · Message contract exported to ROS nodes.
- Interfaces → OutputControl: defines · Service contract exported to ROS nodes.
- Launch → Turtlesim: starts · Launch composition targets the simulator runtime.
- Launch → C++ topic: runs · Launch can coordinate demo nodes.
- Launch → Python topic: runs · Launch can coordinate demo nodes.
- Launch → C++ service: runs · Launch can coordinate demo nodes.
- Launch → Python service: runs · Launch can coordinate demo nodes.
- C++ topic → Spiral pub: contains · C++ publisher example.
- C++ topic → Spiral sub: contains · C++ subscriber example.
- Spiral pub → Spiral sub: topic flow · Publisher stream is consumed by the subscriber.
- Python topic → Spiral pub: contains · Python publisher example.
- Python topic → Spiral sub: contains · Python subscriber example.
- Spiral pub → Spiral sub: topic flow · Publisher stream is consumed by the subscriber.
- C++ service → Polar client: contains · C++ service client example.
- C++ service → Polar server: contains · C++ service server example.
- Polar client → Polar server: service flow · Client request is handled by the server.
- Python service → Polar client: contains · Python service client example.
- Python service → Polar server: contains · Python service server example.
- Polar client → Polar server: service flow · Client request is handled by the server.
- Spiral pub → Interfaces: uses · C++ nodes share ROS contracts from the interface package.
- Spiral sub → Interfaces: uses · C++ nodes share ROS contracts from the interface package.
- Polar client → Interfaces: uses · C++ service client uses shared service schema.
- Polar server → Interfaces: uses · C++ service server uses shared service schema.
- Spiral pub → Interfaces: uses · Python nodes share ROS contracts from the interface package.
- Spiral sub → Interfaces: uses · Python nodes share ROS contracts from the interface package.
- Polar client → Interfaces: uses · Python service client uses shared service schema.
- Polar server → Interfaces: uses · Python service server uses shared service schema.
- IO control → Launch: pairs with · UI is a standalone control artifact alongside the demo launch layer.