# atinfinity/toio_ros2 architecture

> Architecture diagram of the GitHub repository atinfinity/toio_ros2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atinfinity/toio_ros2
- Repository: https://github.com/atinfinity/toio_ros2

## Overview

#### Purpose and runtime

`toio_ros2` is a ROS 2 Python package that bridges a Bluetooth-connected toio Core Cube into standard ROS interfaces. It targets Ubuntu 24.04 / ROS 2 Jazzy and relies on the external `toio.py` library for cube communication. Package metadata and Python installation are defined in `package.xml` and `setup.py`.

#### Entry points and deployment

The main runtime node is `toio_ros2/toio_ros2_node.py`. Normal deployment uses the ROS launch entry point `launch/toio_ros2_bringup.launch.py`, which starts the node and supplies a play-mat parameter file. RViz visualization is supported through `rviz/toio.rviz`.

#### ROS command ingress

The node accepts velocity and pose goals at ROS boundaries:
- `/cmd_vel` (`geometry_msgs/msg/Twist`) for direct desired linear/angular motion.
- `/goal_pose` (`geometry_msgs/msg/PoseStamped`) for desired map-frame positioning.

These inputs enter the control logic in `toio_ros2/toio_ros2_node.py`, where ROS-level commands must be translated into cube motion commands through `toio.py`.

#### Cube connection and hardware boundary

`toio_ros2/toio_ros2_node.py` owns the hardware integration boundary: connecting to the toio Core Cube, reading its position-ID and battery state, and issuing motor/control commands. Bluetooth transport and device protocol behavior are delegated to the external `toio.py` runtime rather than implemented in this repository.

#### Pose normalization and coordinate model

Physical position-ID coordinates from the play mat are converted into a ROS map-coordinate system using configurable field bounds and physical dimensions. The launch flow defaults to A4 mat calibration in `params/toio_a4_play_mat_params.yaml`; an A3 alternative is available at `params/toio_a3_play_mat_params.yaml`. This parameterized transform is the key portability boundary between toio hardware mats and ROS metric navigation.

#### ROS state egress and transforms

The node publishes cube state as:
- `/toio/pose` (`PoseStamped`) in the `map` frame.
- `/toio/battery_level` (`Float32`).
- TF transform from `map` to `center`.

Publishing and TF broadcast behavior are implemented in `toio_ros2/toio_ros2_node.py`. Consumers such as RViz, teleoperation, or navigation-oriented ROS nodes interact only through these ROS topics and frames.

#### Launch configuration and visualization

`launch/toio_ros2_bringup.launch.py` exposes a `params_file` launch argument and defaults it to the A4 calibration YAML. This separates site-specific mat geometry from node code. `rviz/toio.rviz` provides the expected visualization setup for the published pose and transform tree.

Main entry points: [`toio_ros2/toio_ros2_node.py`](https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py) (toio_ros2 node), [`launch/toio_ros2_bringup.launch.py`](https://github.com/atinfinity/toio_ros2/blob/jazzy/launch/toio_ros2_bringup.launch.py) (Bringup launch), [`setup.py`](https://github.com/atinfinity/toio_ros2/blob/jazzy/setup.py) (Python setup), [`rviz/toio.rviz`](https://github.com/atinfinity/toio_ros2/blob/jazzy/rviz/toio.rviz) (RViz setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_deployment["Deployment"]
  node_package_metadata["Package metadata<br/>ROS 2 package<br/>[package.xml]"]
  node_python_setup["Python setup<br/>packaging<br/>[setup.py]"]
  node_bringup_launch["Bringup launch<br/>ROS 2 launch"]
  node_a4_params["A4 mat calibration<br/>parameter YAML"]
  node_a3_params["A3 mat calibration<br/>parameter YAML"]
  node_rviz["RViz setup<br/>visualization config<br/>[toio.rviz]"]
end

subgraph group_ros_interfaces["ROS interfaces"]
  node_cmd_vel["/cmd_vel<br/>Twist input"]
  node_goal_pose["/goal_pose<br/>PoseStamped input"]
  node_toio_pose["/toio/pose<br/>PoseStamped output"]
  node_battery_level["/toio/battery_level<br/>Float32 output"]
  node_map_center_tf["map → center TF<br/>transform output"]
end

subgraph group_node["Bridge node"]
  node_bridge_node["toio_ros2 node<br/>ROS 2 Python node<br/>[toio_ros2_node.py]"]
  node_command_translation["Command translation<br/>control layer<br/>[toio_ros2_node.py]"]
  node_pose_normalization["Pose normalization<br/>coordinate transform<br/>[toio_ros2_node.py]"]
end

subgraph group_hardware["Cube hardware"]
  node_toio_py{{"toio.py<br/>external library"}}
  node_core_cube(("toio Core Cube<br/>Bluetooth hardware"))
end

node_package_metadata -->|"packages"| node_python_setup
node_python_setup -->|"installs"| node_bridge_node
node_bringup_launch -->|"starts"| node_bridge_node
node_a4_params -->|"default params_file"| node_bringup_launch
node_a3_params -.->|"alternative params_file"| node_bringup_launch
node_bringup_launch -->|"loads calibration"| node_pose_normalization
node_cmd_vel -->|"velocity command"| node_command_translation
node_goal_pose -->|"pose goal"| node_command_translation
node_command_translation -->|"cube control"| node_bridge_node
node_bridge_node -->|"uses"| node_toio_py
node_toio_py -->|"Bluetooth protocol"| node_core_cube
node_core_cube -->|"position-ID and battery"| node_toio_py
node_toio_py -->|"cube state"| node_bridge_node
node_bridge_node -->|"physical coordinates"| node_pose_normalization
node_pose_normalization -->|"map-frame pose"| node_toio_pose
node_pose_normalization -->|"map to center"| node_map_center_tf
node_bridge_node -->|"battery state"| node_battery_level
node_toio_pose -.->|"visualizes"| node_rviz
node_map_center_tf -.->|"visualizes"| node_rviz

click node_package_metadata "https://github.com/atinfinity/toio_ros2/blob/jazzy/package.xml"
click node_python_setup "https://github.com/atinfinity/toio_ros2/blob/jazzy/setup.py"
click node_bringup_launch "https://github.com/atinfinity/toio_ros2/blob/jazzy/launch/toio_ros2_bringup.launch.py"
click node_a4_params "https://github.com/atinfinity/toio_ros2/blob/jazzy/params/toio_a4_play_mat_params.yaml"
click node_a3_params "https://github.com/atinfinity/toio_ros2/blob/jazzy/params/toio_a3_play_mat_params.yaml"
click node_bridge_node "https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py"
click node_command_translation "https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py"
click node_pose_normalization "https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py"
click node_rviz "https://github.com/atinfinity/toio_ros2/blob/jazzy/rviz/toio.rviz"

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_package_metadata,node_python_setup,node_bringup_launch,node_a4_params,node_a3_params,node_rviz toneBlue
class node_cmd_vel,node_goal_pose,node_toio_pose,node_battery_level,node_map_center_tf toneAmber
class node_bridge_node,node_command_translation,node_pose_normalization toneMint
class node_toio_py,node_core_cube toneRose
```

## Components

### Deployment

- [Package metadata](https://github.com/atinfinity/toio_ros2/blob/jazzy/package.xml): ROS 2 package · Defines package metadata and Python installation. · `package.xml`
- [Python setup](https://github.com/atinfinity/toio_ros2/blob/jazzy/setup.py): packaging · `setup.py`
- [Bringup launch](https://github.com/atinfinity/toio_ros2/blob/jazzy/launch/toio_ros2_bringup.launch.py): ROS 2 launch · Starts the bridge with a selectable mat calibration. · `launch/toio_ros2_bringup.launch.py`
- [A4 mat calibration](https://github.com/atinfinity/toio_ros2/blob/jazzy/params/toio_a4_play_mat_params.yaml): parameter YAML · Default play-mat geometry and field bounds. · `params/toio_a4_play_mat_params.yaml`
- [A3 mat calibration](https://github.com/atinfinity/toio_ros2/blob/jazzy/params/toio_a3_play_mat_params.yaml): parameter YAML · Alternative play-mat geometry and field bounds. · `params/toio_a3_play_mat_params.yaml`
- [RViz setup](https://github.com/atinfinity/toio_ros2/blob/jazzy/rviz/toio.rviz): visualization config · Visualizes published pose and transform tree. · `rviz/toio.rviz`

### ROS interfaces

- **/cmd_vel**: Twist input · Direct desired linear and angular motion.
- **/goal_pose**: PoseStamped input · Desired map-frame position.
- **/toio/pose**: PoseStamped output · Cube pose in the map frame.
- **/toio/battery_level**: Float32 output
- **map → center TF**: transform output

### Bridge node

- [toio_ros2 node](https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py): ROS 2 Python node · Owns ROS interfaces, cube I/O, state publication, and TF broadcast. · `toio_ros2/toio_ros2_node.py`
- [Command translation](https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py): control layer · Converts Twist and pose goals into cube motion commands. · `toio_ros2/toio_ros2_node.py`
- [Pose normalization](https://github.com/atinfinity/toio_ros2/blob/jazzy/toio_ros2/toio_ros2_node.py): coordinate transform · Converts position-ID coordinates to metric map coordinates. · `toio_ros2/toio_ros2_node.py`

### Cube hardware

- **toio.py**: external library · Provides Bluetooth transport and cube protocol behavior.
- **toio Core Cube**: Bluetooth hardware · Provides position-ID and battery state and receives motor commands.

## Connections

- Package metadata → Python setup: packages
- Python setup → toio_ros2 node: installs
- Bringup launch → toio_ros2 node: starts
- A4 mat calibration → Bringup launch: default params_file
- A3 mat calibration → Bringup launch: alternative params_file
- Bringup launch → Pose normalization: loads calibration
- /cmd_vel → Command translation: velocity command
- /goal_pose → Command translation: pose goal
- Command translation → toio_ros2 node: cube control
- toio_ros2 node → toio.py: uses
- toio.py → toio Core Cube: Bluetooth protocol
- toio Core Cube → toio.py: position-ID and battery
- toio.py → toio_ros2 node: cube state
- toio_ros2 node → Pose normalization: physical coordinates
- Pose normalization → /toio/pose: map-frame pose
- Pose normalization → map → center TF: map to center
- toio_ros2 node → /toio/battery_level: battery state
- /toio/pose → RViz setup: visualizes
- map → center TF → RViz setup: visualizes
