# elena-ecn/quadrotor_mpc architecture

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

- Interactive diagram: https://gitdiagram.com/elena-ecn/quadrotor_mpc
- Repository: https://github.com/elena-ecn/quadrotor_mpc

## Overview

##### Main Components
- Core MPC Controller: Represented by mpc.py – this module computes the optimal control inputs using the MPC formulation described in the README.
- Simulation/Main Process: main.py is the entry point. It ties together the setup, MPC computations, and simulation loop.
- Configuration Module: config.py that stores parameters and settings used across the simulation.
- Plotting and Visualization: plotter.py, which handles results visualization and potentially feeding data into animations.
- Utility Functions: utils.py provides helper methods that support various parts of the simulation.
- Animation Module: The Animation directory holds resources to animate quadrotor trajectories. Inside, there are a Jupyter notebook (quadrotor_animation.ipynb) and scripts (e.g., utils/quadrotor.jl) which indicate a secondary pipeline (based on Julia) for either advanced animation or postprocessing.
- Data Files: CSV files (X_quadrotor.csv, X_ref.csv) in the Animation folder, which likely store simulation trajectories or reference data.

##### Understand the Relationships and Data Flow
- main.py acts as the orchestrator:
- It likely loads configuration parameters from config.py.
- Calls mpc.py to compute control actions at each time step.
- Uses utils.py to support simulation calculations.
- Sends generated data to plotter.py, which then visualizes the quadrotor's performance.
- The MPC algorithm computes trajectories based on optimization (with cvxpy) and prints or logs results.
- The Animation module takes simulation output (or stored CSV files) to generate an animated view of the quadrotor flight, emphasizing the differences between the executed trajectory and the reference trajectory.
- The images directory provides static images (like drone_image.png) that are used in the README and might be used within the visualization modules.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each component (MPC, simulation orchestration, plotting, and animation) is organized into its own module/directory.
- Modularity: Utility functions, configurations, and specialized tasks (like animation) are separated, allowing easy updates and testing.
- Multi-Language Integration: Note the use of Python for control and simulation and Julia for animation (if the Julia scripts in Animation/utils are actively used).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Simulation Components
    subgraph "Core Simulation Components"
        config["Configuration Manager (config.py)"]
        main["Main Simulation Engine (main.py)"]
        mpc["MPC Controller (mpc.py)"]
        utils["Utility Functions (utils.py)"]
        plotter["Plotting & Visualization (plotter.py)"]
    end

    %% Animation and Data Components
    subgraph "Animation and Data Components"
        ani_nb["Animation Notebook (Animation/quadrotor_animation.ipynb)"]
        ani_jl["Julia Animation Scripts (Animation/utils/quadrotor.jl)"]
        traj["Trajectory Data (Animation/X_quadrotor.csv)"]
        ref["Reference Data (Animation/X_ref.csv)"]
    end

    %% Data Flow in Core Simulation
    config --> main
    config --> mpc
    main --> mpc
    main --> utils
    main --> plotter
    main -->|"sends_simulation_output"| ani_nb
    main -->|"sends_simulation_output"| ani_jl

    %% Data Flow in Visualization and Animation
    plotter -->|"visualizes"| ani_nb
    plotter -->|"visualizes"| ani_jl
    ani_nb -->|"reads_data"| traj
    ani_nb -->|"reads_data"| ref
    ani_jl -->|"reads_data"| traj
    ani_jl -->|"reads_data"| ref

    %% Styles
    classDef comp fill:#a8d5e2,stroke:#036,stroke-width:2px;
    classDef vis fill:#d0f0c0,stroke:#030,stroke-width:2px;
    classDef data fill:#f9cb9c,stroke:#d35400,stroke-width:2px;

    class config,main,mpc,utils comp;
    class plotter,ani_nb,ani_jl vis;
    class traj,ref data;

    %% Click Events
    click config "https://github.com/elena-ecn/quadrotor_mpc/blob/main/config.py"
    click main "https://github.com/elena-ecn/quadrotor_mpc/blob/main/main.py"
    click mpc "https://github.com/elena-ecn/quadrotor_mpc/blob/main/mpc.py"
    click utils "https://github.com/elena-ecn/quadrotor_mpc/blob/main/utils.py"
    click plotter "https://github.com/elena-ecn/quadrotor_mpc/blob/main/plotter.py"
    click ani_nb "https://github.com/elena-ecn/quadrotor_mpc/blob/main/Animation/quadrotor_animation.ipynb"
    click ani_jl "https://github.com/elena-ecn/quadrotor_mpc/blob/main/Animation/utils/quadrotor.jl"
    click traj "https://github.com/elena-ecn/quadrotor_mpc/blob/main/Animation/X_quadrotor.csv"
    click ref "https://github.com/elena-ecn/quadrotor_mpc/blob/main/Animation/X_ref.csv"
```
