# zitongbai/aruco_tf architecture

> Architecture diagram of the GitHub repository zitongbai/aruco_tf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zitongbai/aruco_tf
- Repository: https://github.com/zitongbai/aruco_tf

## Overview

##### Project Type and Purpose
- This is a ROS (Robot Operating System) package named **aruco_tf**.
- Its goal is to detect ArUco markers in a camera feed using OpenCV, then publish the marker’s pose into the ROS tf tree so that other ROS nodes (e.g., visualization or motion planners) can consume it.
- It also includes a calibration subsystem to compute camera intrinsics before detection.

##### File‐Structure Analysis
Top level:
- CMakeLists.txt & package.xml → ROS build and dependency descriptors
- launch/ → ROS launch files
- rviz/ → RViz configuration (aruco_tf.rviz)
- src/ → Python source code
– src/calibrate/ → calibration scripts (take_pic.py, calibrate.py)
– cam.py → camera interface node
– detect.py → ArUco detection & tf broadcaster
Indicators:
- Node-based architecture following standard ROS package layout.
- Launch file to glue together camera, calibration, and detection nodes.
- RViz config for visualization of the published tf frames.

##### Additional Insights from README
- Dependencies: ROS (catkin), OpenCV, numpy, cv_bridge, tf.
- Workflow: (1) capture chessboard images → (2) compute calibration → (3) run detection & broadcast tf.
- A single launch file (`detect_aruco.launch`) orchestrates the detection phase.

##### Main Components
a. ROS Master
b. Camera Driver Node (cam.py)
c. Calibration Node (take_pic.py & calibrate.py)
d. Detection Node (detect.py)
e. Calibration Data Store (calib.npz)
f. tf Broadcaster (inside detect.py)
g. RViz GUI (aruco_tf.rviz)
h. Launch File (detect_aruco.launch)

##### Relationships & Data Flows
- **Launch File** starts → ROS Master + all nodes
- **Camera Node** publishes `/camera/image_raw`
- **Calibration Node** subscribes to `/camera/image_raw`
→ captures chessboard images → writes `calib.npz`
- **Detection Node** loads `calib.npz` → subscribes to `/camera/image_raw`
→ OpenCV ArUco detector → publishes transforms on `/tf`
- **RViz** subscribes to `/tf` → visualizes marker frame

##### Architectural Patterns & Design Principles
- **Modularity**: Separate nodes for calibration vs. detection vs. camera interface
- **ROS Pub/Sub**: decoupled communication via topics (`/camera/image_raw`)
- **Launch‐time composition**: launch file as the composition root
- **Reusability**: camera node and calibration scripts can be reused in other ROS setups

##### Technologies & Frameworks
- ROS (rospy, tf, cv_bridge)
- OpenCV (cv2) for image processing and ArUco detection
- NumPy for calibration data storage (`.npz` file)
- RViz for 3D visualization

##### Final Checklist
- Clear, descriptive labels for each node, topic, file, and tool.
- Callouts for any key parameters (e.g., chessboard size, marker dictionary).

## Diagram (Mermaid)

```mermaid
flowchart TD
    L(("detect_aruco.launch")):::launch
    RM["ROS Master"]:::master
    RV["RViz GUI\n(aruco_tf.rviz)"]:::gui

    subgraph "ROS Nodes"
        direction TB
        Cam["Camera Node\n(cam.py)"]:::node
        TP["Calibration Capture\n(take_pic.py)"]:::node
        Cal["Calibration Compute\n(calibrate.py)"]:::node
        Det["Detection Node\n(detect.py)"]:::node
    end

    D[(calib.npz)]:::data

    %% Startup flows
    L --> RM
    L --> Cam
    L --> TP
    L --> Cal
    L --> Det

    %% Data flows
    Cam -->|"publishes /camera/image_raw"| TP
    Cam -->|"publishes /camera/image_raw"| Det
    TP -->|"writes calib.npz"| D
    Cal -->|"writes calib.npz"| D
    D -->|"loads calib.npz"| Det
    Det -->|"publishes transforms on /tf"| RM
    RM -->|"provides /tf"| RV

    %% Click Events
    click L "https://github.com/zitongbai/aruco_tf/blob/main/launch/detect_aruco.launch"
    click RV "https://github.com/zitongbai/aruco_tf/blob/main/rviz/aruco_tf.rviz"
    click Cam "https://github.com/zitongbai/aruco_tf/blob/main/src/cam.py"
    click TP "https://github.com/zitongbai/aruco_tf/blob/main/src/calibrate/take_pic.py"
    click Cal "https://github.com/zitongbai/aruco_tf/blob/main/src/calibrate/calibrate.py"
    click Det "https://github.com/zitongbai/aruco_tf/blob/main/src/detect.py"

    %% Styles
    classDef node fill:#add8e6,stroke:#000,stroke-width:1px
    classDef data fill:#90ee90,stroke:#000,stroke-width:1px
    classDef master fill:#ffa500,stroke:#000,stroke-width:1px
    classDef gui fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef launch fill:#ffdead,stroke:#000,stroke-width:1px
```
