# forzaeth/race_stack architecture

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

- Interactive diagram: https://gitdiagram.com/forzaeth/race_stack
- Repository: https://github.com/forzaeth/race_stack

## Overview

This project is a full-stack autonomous racing system built for scaled race cars, integrating simulation, real‐car hardware, and various state-of-the-art modules. Its purpose is to provide an end-to-end solution for head-to-head autonomous racing; it includes everything from low-level control and state estimation to high-level planning, perception, and system identification, as well as simulation support. The design has deep roots in ROS-based architectures and leverages several well-known open source projects.

##### Major Components and Layers
- Base System & Stack Master: Representing the main entry point that ties together the various modules for deployment on the car or in simulation.
- Controller and f110_utils: Low-level control, message definitions, and utility libraries for interfacing with the car hardware and simulation. Include the “controller” folder and the “f110_utils” libraries (which include message definitions [e.g., CarState, Waypoints], conversion utilities, and node implementations).
- Perception: Handling sensor processing and object/opponent tracking (e.g., the “perception” directory with its opponent_tracker module).
- Planner: This module covers path planning, trajectory optimization, and graph-based planning. It includes both traditional optimal planning (frenet-planner) and global planners implemented under the “planner” directory.
- State Estimation & State Machine: Running the fuse of sensor data and feedback through modules like “state_estimation” and “state_machine” which govern the overall behavioral logic of the vehicle.
- System Identification: This sub-system, under “system_identification”, is responsible for on-track system identification and performance tuning.
- Simulation and Deployment Infrastructure: Includes docker and container configurations, “docker-compose”, and “devcontainer” scripts, as well as associated launch files for simulation (both hardware and software in a ROS environment).
- Supporting modules: Additional libraries (e.g., cartographer integrations, predictive spliner, mapping, etc.) and configuration files (often YAML/CMakeLists) that bind the components.

##### Relationships and Data Flow
- Data flow can be segmented by layers. For example, sensor data from the perception system feeds into state estimation; then the state machine uses this processed information to update control commands that pass to the controller.
- The high-level planner (which may operate via the planner and global optimizer nodes) consumes route designs and data from perception to generate trajectories.
- Deployment orchestration is managed by “stack_master”, which composes launch files and configurations for both simulation and hardware.

##### Architectural Patterns and Design Principles
- Modularity and separation of concerns: Each module (perception, planning, state estimation, control, system identification) is a self-contained ROS node or set of nodes.
- Publisher-subscriber communication: ROS topics and services are used extensively.
- Use of configuration files and launch scripts: Many folders contain launch, configuration (YAML, .cfg), and parameter files that drive the operation.
- Hybrid usage of C++ and Python: Some nodes are implemented in C++ (for performance-critical parts, e.g., in controller and planner implementations) and others in Python (for orchestration, state machine, etc.).
- Containerization for reproducibility: Dockerfiles and devcontainer configurations provide a containerized environment.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Layer 1: Base Integration
  subgraph "Layer 1: Base Integration"
    BS["Base System"]:::base
  end

  %% Layer 2: Deployment Infrastructure
  subgraph "Layer 2: Deployment Infrastructure"
    SM["Stack Master / Deployment"]:::deploy
    DC[".devcontainer"]:::deploy
    DU[".docker_utils"]:::deploy
    DCY["docker-compose.yaml"]:::deploy
  end

  %% Layer 3: Low-Level Control Layer
  subgraph "Layer 3: Low-Level Control Layer"
    CTR["Controller"]:::control
    F110["f110_utils"]:::control
  end

  %% Layer 4: Perception & State Estimation Layer
  subgraph "Layer 4: Perception & State Estimation Layer"
    PER["Perception"]:::perception
    SE["State Estimation"]:::state
    STM["State Machine"]:::state
  end

  %% Layer 5: High-Level Planning Layer
  subgraph "Layer 5: High-Level Planning Layer"
    PL["Planner"]:::planning
  end

  %% Layer 6: System Identification
  subgraph "Layer 6: System Identification"
    SI["System Identification"]:::sysid
  end

  %% Data Flow Relationships
  BS --> SM
  SM --> CTR
  SM --> PL
  SM --> PER
  SM --> SE
  SM --> STM
  SM --> SI

  PER -->|"sensor data"| SE
  SI -->|"identification data"| SE
  SE -->|"state update"| STM
  SE -->|"trajectory request"| PL
  PL -->|"control commands"| CTR
  F110 -->|"utility functions"| CTR

  %% Legend
  subgraph "Legend: Color Coding"
    L1["Base Integration: Base System (orange)"]:::baseLegend
    L2["Deployment: Stack Master & Config (blue)"]:::deployLegend
    L3["Low-Level Control: Controller, f110_utils (red)"]:::controlLegend
    L4["Perception & State Estimation: Perception, State Estimation, State Machine (green)"]:::stateLegend
    L5["High-Level Planning: Planner (purple)"]:::planningLegend
    L6["System Identification: System Identification (cyan)"]:::sysidLegend
  end

  %% Click Events
  click BS "https://github.com/forzaeth/race_stack/tree/main/base_system"
  click SM "https://github.com/forzaeth/race_stack/tree/main/stack_master"
  click CTR "https://github.com/forzaeth/race_stack/tree/main/controller"
  click F110 "https://github.com/forzaeth/race_stack/tree/main/f110_utils"
  click PER "https://github.com/forzaeth/race_stack/tree/main/perception"
  click PL "https://github.com/forzaeth/race_stack/tree/main/planner"
  click SE "https://github.com/forzaeth/race_stack/tree/main/state_estimation"
  click STM "https://github.com/forzaeth/race_stack/tree/main/state_machine"
  click SI "https://github.com/forzaeth/race_stack/tree/main/system_identification"
  click DC "https://github.com/forzaeth/race_stack/blob/main/.devcontainer"
  click DU "https://github.com/forzaeth/race_stack/blob/main/.docker_utils"
  click DCY "https://github.com/forzaeth/race_stack/blob/main/docker-compose.yaml"

%% Class Definitions for main nodes
classDef base fill:#FFA500,stroke:#333,stroke-width:2px;
classDef deploy fill:#6fa8dc,stroke:#333,stroke-width:2px;
classDef control fill:#ff6961,stroke:#333,stroke-width:2px;
classDef perception fill:#fdfd96,stroke:#333,stroke-width:2px;
classDef state fill:#77dd77,stroke:#333,stroke-width:2px;
classDef planning fill:#967bb6,stroke:#333,stroke-width:2px;
classDef sysid fill:#56b4d3,stroke:#333,stroke-width:2px;

%% Class Definitions for legend nodes
classDef baseLegend fill:#FFA500,stroke:#333,stroke-width:1px, font-size:12px;
classDef deployLegend fill:#6fa8dc,stroke:#333,stroke-width:1px, font-size:12px;
classDef controlLegend fill:#ff6961,stroke:#333,stroke-width:1px, font-size:12px;
classDef stateLegend fill:#77dd77,stroke:#333,stroke-width:1px, font-size:12px;
classDef planningLegend fill:#967bb6,stroke:#333,stroke-width:1px, font-size:12px;
classDef sysidLegend fill:#56b4d3,stroke:#333,stroke-width:1px, font-size:12px;
```
