# packtpublishing/ros-2-from-scratch architecture

> Architecture diagram of the GitHub repository packtpublishing/ros-2-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/packtpublishing/ros-2-from-scratch
- Repository: https://github.com/packtpublishing/ros-2-from-scratch

## Overview

This repository is a chapter-by-chapter set of ROS 2 learning examples, not one integrated robot application. A representative runtime workflow is to start a node, exchange topic or service/action messages with other nodes, and observe results; the later chapters add a turtle controller and launch examples. The README also describes robot-description, TF, RViz, and Gazebo topics, but the supplied tree does not expose enough implementation to map those workflows in detail. The graph uses sampled controller code and tree-supported example paths; wiring to unsampled implementations is omitted.

Main entry points: [`ch9/turtle_controller/turtle_controller/turtle_controller.py`](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller/turtle_controller/turtle_controller.py) (Turtle controller), [`ch9/turtle_controller_cpp/src/turtle_controller.cpp`](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller_cpp/src/turtle_controller.cpp) (C++ turtle controller), [`ch7/my_py_pkg/my_py_pkg/count_until_client.py`](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/count_until_client.py) (Count action client), [`ch7/my_py_pkg/my_py_pkg/number_counter.py`](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/number_counter.py) (Number counter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_examples["ROS examples"]
  node_first_py["Python node<br/>[my_first_node.py]"]
  node_first_cpp["C++ node<br/>[my_first_node.cpp]"]
  node_publisher["Number publisher"]
  node_counter["Number counter<br/>[number_counter.py]"]
  node_reset_client["Reset client"]
  node_action_client["Count action client"]
  node_action_server["Count action server"]
  node_cpp_action_client["C++ action client"]
  node_cpp_action_server["C++ action server"]
  node_number_launch["Number app launch"]
end

subgraph group_turtle["Turtle control"]
  node_controller_py["Turtle controller"]
  node_controller_cpp["C++ turtle controller"]
  node_turtle_launch["Turtle launch"]
end

subgraph group_interfaces["ROS interfaces"]
  node_activate["Activation service<br/>[CMakeLists.txt]"]
  node_count_interface["Count action interface<br/>[CMakeLists.txt]"]
  node_number_interface["Number/reset interfaces<br/>[CMakeLists.txt]"]
end

subgraph group_robot["Robot description"]
  node_description["Robot description launch<br/>[display.launch.py]"]
  node_robot_model["Robot model / TF"]
end

node_developer(("ROS user"))
node_ros{{"ROS 2 runtime"}}
node_turtlesim{{"Turtlesim"}}
node_operator(("Controller operator"))

node_developer -->|"runs node"| node_first_py
node_developer -->|"runs node"| node_first_cpp
node_developer -->|"starts example"| node_number_launch
node_number_launch -->|"launches"| node_publisher
node_number_launch -->|"launches"| node_counter
node_publisher -->|"publishes numbers"| node_ros
node_ros -->|"delivers numbers"| node_counter
node_reset_client -->|"requests reset"| node_counter
node_developer -->|"runs client"| node_action_client
node_action_client -->|"sends goals"| node_action_server
node_action_client -->|"uses action transport"| node_ros
node_cpp_action_client -->|"sends goals"| node_cpp_action_server
node_cpp_action_client -->|"uses action transport"| node_ros
node_developer -->|"starts example"| node_turtle_launch
node_turtle_launch -->|"launches"| node_controller_py
node_controller_py -->|"reads pose"| node_turtlesim
node_controller_py -->|"publishes motion"| node_turtlesim
node_controller_py -->|"requests pen change"| node_turtlesim
node_operator -->|"activates service"| node_controller_py
node_controller_cpp -->|"reads pose"| node_turtlesim
node_controller_cpp -->|"publishes motion"| node_turtlesim
node_controller_cpp -->|"requests pen change"| node_turtlesim
node_operator -->|"activates service"| node_controller_cpp
node_controller_py -->|"implements service"| node_activate
node_controller_cpp -->|"implements service"| node_activate
node_action_client -->|"uses type"| node_count_interface
node_action_server -->|"uses type"| node_count_interface
node_cpp_action_client -->|"uses type"| node_count_interface
node_cpp_action_server -->|"uses type"| node_count_interface
node_publisher -->|"uses type"| node_number_interface
node_counter -->|"uses type"| node_number_interface
node_reset_client -->|"uses type"| node_number_interface
node_developer -->|"starts display"| node_description
node_description -->|"loads description"| node_robot_model

click node_first_py "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch4/my_py_pkg/my_py_pkg/my_first_node.py"
click node_first_cpp "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch4/my_cpp_pkg/src/my_first_node.cpp"
click node_publisher "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/number_publisher.py"
click node_counter "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/number_counter.py"
click node_reset_client "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/reset_counter_client.py"
click node_action_client "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/count_until_client.py"
click node_action_server "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/count_until_server.py"
click node_cpp_action_client "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_cpp_pkg/src/count_until_client.cpp"
click node_cpp_action_server "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_cpp_pkg/src/count_until_server.cpp"
click node_controller_py "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller/turtle_controller/turtle_controller.py"
click node_controller_cpp "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller_cpp/src/turtle_controller.cpp"
click node_activate "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_interfaces/CMakeLists.txt"
click node_count_interface "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_robot_interfaces/CMakeLists.txt"
click node_number_interface "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_robot_interfaces/CMakeLists.txt"
click node_number_launch "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_bringup/launch/number_app.launch.py"
click node_turtle_launch "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_bringup/launch/turtlesim_control.launch.py"
click node_description "https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch13/my_robot_description/launch/display.launch.py"
click node_robot_model "https://github.com/packtpublishing/ros-2-from-scratch/tree/main/ch13/my_robot_description"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_first_py,node_first_cpp,node_publisher,node_counter,node_reset_client,node_action_client,node_action_server,node_cpp_action_client,node_cpp_action_server,node_number_launch,node_developer toneBlue
class node_controller_py,node_controller_cpp,node_turtle_launch toneAmber
class node_activate,node_count_interface,node_number_interface toneMint
class node_description,node_robot_model toneRose
class node_ros,node_turtlesim,node_operator toneIndigo
```

## Components

### ROS examples

- [Python node](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch4/my_py_pkg/my_py_pkg/my_first_node.py): `ch4/my_py_pkg/my_py_pkg/my_first_node.py`
- [C++ node](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch4/my_cpp_pkg/src/my_first_node.cpp): `ch4/my_cpp_pkg/src/my_first_node.cpp`
- [Number publisher](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/number_publisher.py): `ch7/my_py_pkg/my_py_pkg/number_publisher.py`
- [Number counter](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/number_counter.py): `ch7/my_py_pkg/my_py_pkg/number_counter.py`
- [Reset client](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/reset_counter_client.py): `ch7/my_py_pkg/my_py_pkg/reset_counter_client.py`
- [Count action client](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/count_until_client.py): `ch7/my_py_pkg/my_py_pkg/count_until_client.py`
- [Count action server](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_py_pkg/my_py_pkg/count_until_server.py): `ch7/my_py_pkg/my_py_pkg/count_until_server.py`
- [C++ action client](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_cpp_pkg/src/count_until_client.cpp): `ch7/my_cpp_pkg/src/count_until_client.cpp`
- [C++ action server](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_cpp_pkg/src/count_until_server.cpp): `ch7/my_cpp_pkg/src/count_until_server.cpp`
- [Number app launch](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_bringup/launch/number_app.launch.py): `ch9/my_robot_bringup/launch/number_app.launch.py`

### Turtle control

- [Turtle controller](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller/turtle_controller/turtle_controller.py): `ch9/turtle_controller/turtle_controller/turtle_controller.py`
- [C++ turtle controller](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/turtle_controller_cpp/src/turtle_controller.cpp): `ch9/turtle_controller_cpp/src/turtle_controller.cpp`
- [Turtle launch](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_bringup/launch/turtlesim_control.launch.py): `ch9/my_robot_bringup/launch/turtlesim_control.launch.py`

### ROS interfaces

- [Activation service](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch9/my_robot_interfaces/CMakeLists.txt): `ch9/my_robot_interfaces/CMakeLists.txt`
- [Count action interface](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_robot_interfaces/CMakeLists.txt): `ch7/my_robot_interfaces/CMakeLists.txt`
- [Number/reset interfaces](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch7/my_robot_interfaces/CMakeLists.txt): `ch7/my_robot_interfaces/CMakeLists.txt`

### Robot description

- [Robot description launch](https://github.com/packtpublishing/ros-2-from-scratch/blob/main/ch13/my_robot_description/launch/display.launch.py): `ch13/my_robot_description/launch/display.launch.py`
- [Robot model / TF](https://github.com/packtpublishing/ros-2-from-scratch/tree/main/ch13/my_robot_description): `ch13/my_robot_description`

### Other components

- **ROS user**
- **ROS 2 runtime**
- **Turtlesim**
- **Controller operator**

## Connections

- ROS user → Python node: runs node
- ROS user → C++ node: runs node
- ROS user → Number app launch: starts example
- Number app launch → Number publisher: launches
- Number app launch → Number counter: launches
- Number publisher → ROS 2 runtime: publishes numbers
- ROS 2 runtime → Number counter: delivers numbers
- Reset client → Number counter: requests reset
- ROS user → Count action client: runs client
- Count action client → Count action server: sends goals
- Count action client → ROS 2 runtime: uses action transport
- C++ action client → C++ action server: sends goals
- C++ action client → ROS 2 runtime: uses action transport
- ROS user → Turtle launch: starts example
- Turtle launch → Turtle controller: launches
- Turtle controller → Turtlesim: reads pose
- Turtle controller → Turtlesim: publishes motion
- Turtle controller → Turtlesim: requests pen change
- Controller operator → Turtle controller: activates service
- C++ turtle controller → Turtlesim: reads pose
- C++ turtle controller → Turtlesim: publishes motion
- C++ turtle controller → Turtlesim: requests pen change
- Controller operator → C++ turtle controller: activates service
- Turtle controller → Activation service: implements service
- C++ turtle controller → Activation service: implements service
- Count action client → Count action interface: uses type
- Count action server → Count action interface: uses type
- C++ action client → Count action interface: uses type
- C++ action server → Count action interface: uses type
- Number publisher → Number/reset interfaces: uses type
- Number counter → Number/reset interfaces: uses type
- Reset client → Number/reset interfaces: uses type
- ROS user → Robot description launch: starts display
- Robot description launch → Robot model / TF: loads description
