# arya-mgc/ins-system-for-drone architecture

> Architecture diagram of the GitHub repository arya-mgc/ins-system-for-drone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arya-mgc/ins-system-for-drone
- Repository: https://github.com/arya-mgc/ins-system-for-drone

## Overview

#### Purpose and entry points
This is a MATLAB/Simulink UAV flight-stack simulation and embedded-code-generation architecture for GPS-denied navigation, robust control, and fault handling. Initialize the workspace and contracts through `Runtime/init_all.m`; construct the INS/Simulink integration via `Codegen/build_ins_simulink_model.m`. Primary analysis entry is `Validation/trim_and_linearize.m`.

#### Interface and multi-rate runtime backbone
Cross-domain signals are governed by bus, enum, unit, and sample-rate definitions in `Interfaces/bus_definitions.m`, `Interfaces/signal_enums.m`, and `Interfaces/sample_rates.m`. The scheduler coordinates independent estimator/control/sensor rates, timestamp handling, and injected communication/actuator latency through `Runtime/task_scheduler.m`, `Runtime/sensor_timestamps.m`, and `Runtime/latency_injector.m`. This is the key discrete-time boundary between otherwise asynchronous subsystems.

#### Mission guidance and supervisory behavior
Guidance transforms mission scripts and waypoint state into constrained trajectories and replan decisions. Its control-facing outputs are trajectory/setpoint commands, while safety constraints such as geofencing can alter mission progression. Core paths are `Guidance/mission_script_parser.m`, `Guidance/generate_trajectory.m`, and `Guidance/dynamic_replan.m`; mission-state initialization is in `Guidance/init_state_machine.m`.

#### Feedback control and allocation
The control domain consumes estimated state plus guidance references and produces actuator-level demands. It combines scheduled PID/LQR-oriented control, feedforward, rate limiting, anti-windup, and a control-allocation matrix. Architectural anchors: `Control/gain_schedule_hover_forwardflight.m`, `Control/control_allocation_matrix.m`, and `Control/anti_windup_logic.m`. An experimental MPC path exists in `Control/mpc_experimental.m`, but is not the primary advertised control path.

#### Plant and sensor simulation boundary
The simulated aircraft/environment converts actuator commands into nonlinear vehicle dynamics, including motor/ESC response, thrust/torque lookup behavior, battery sag, drag, and ground/propwash effects. Key components are `Plant/init_plant_params.m`, `Plant/motor_esc_dynamics.m`, and `Plant/thrust_torque_lut.m`. Sensors transform plant state into delayed/noisy/degraded measurements using `Sensors/simulate_imu.m`, `Sensors/gps_dropout_sim.m`, and `Sensors/sensor_bias_drift.m`. Aerospace Blockset models are a stated runtime dependency for 6-DOF/environment modeling.

#### Navigation estimation and FDIR
The estimator consumes asynchronous sensor measurements and maintains a 15-state EKF navigation solution, with quaternion normalization, covariance tuning, reset/dead-reckoning paths, and innovation checks. Core paths: `Estimator/main_advanced_ins.m`, `Estimator/advanced_ekf_core.m`, and `Estimator/innovation_monitor.m`. Fault detection consumes health/innovation/actuation signals and selects degraded or fallback behavior through `Faults/init_fault_detectors.m`, `Faults/ekf_divergence_check.m`, and `Faults/fallback_supervisor_matrix.m`. This layer forms the safety boundary capable of overriding normal mission execution.

#### Verification, logging, and deployment
Scenario scripts drive adversarial simulation inputs; validation runs performance, Monte Carlo, trim/linearization, and stress workflows via `Validation/run_monte_carlo.m`, `Validation/stress_campaign_runner.m`, and `Validation/trim_and_linearize.m`. Outputs flow to replay, telemetry, CSV, and ULog adapters in `Logs/flight_replay.m`, `Logs/telemetry_packetizer.m`, and `Logs/ulog_export.m`. Embedded Coder configuration targets MISRA-oriented ARM Cortex-M C/C++ generation through `Codegen/setup_embedded_coder.m`, `Codegen/misra_c_config.m`, and `Codegen/target_hardware_setup.m`; CI regression is defined in `.github/workflows/sim_regression.yml`. Required material runtimes include MATLAB/Simulink, Stateflow, Simulink Control Design, Aerospace Blockset, and optionally Embedded Coder.

Main entry points: [`Runtime/task_scheduler.m`](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Runtime/task_scheduler.m) (Multi-rate scheduler), [`Plant/motor_esc_dynamics.m`](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Plant/motor_esc_dynamics.m) (Aircraft plant), [`Control/gain_schedule_hover_forwardflight.m`](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Control/gain_schedule_hover_forwardflight.m) (Feedback control), [`Estimator/main_advanced_ins.m`](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Estimator/main_advanced_ins.m) (INS / 15-state EKF)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; Interfaces"]
  node_init["Workspace initialization<br/>MATLAB entry point<br/>[init_all.m]"]
  node_interfaces["Signal contracts<br/>[bus_definitions.m]"]
  node_scheduler["Multi-rate scheduler<br/>discrete-time runtime<br/>[task_scheduler.m]"]
end

subgraph group_flight["Flight Stack"]
  node_guidance["Mission guidance<br/>trajectory &amp; replanning"]
  node_control["Feedback control<br/>scheduled PID/LQR control"]
  node_allocation["Control allocation<br/>actuator mixer"]
  node_estimator["INS / 15-state EKF<br/>navigation estimator"]
  node_ekf_core["EKF core<br/>state estimation kernel"]
  node_fdir{{"FDIR supervisor<br/>safety supervisor"}}
end

subgraph group_simulation["Plant &amp; Sensors"]
  node_plant["Aircraft plant<br/>nonlinear 6-DOF simulation"]
  node_thrust_lut["Thrust / torque LUT<br/>propulsion model"]
  node_sensors["Sensor simulation<br/>noisy degraded measurements<br/>[simulate_imu.m]"]
end

subgraph group_assurance["Validation &amp; Observability"]
  node_validation["Scenario validation"]
  node_trim_linearize["Trim &amp; linearization<br/>analysis entry point"]
  node_logging["Replay &amp; telemetry<br/>output adapters"]
  node_ci["Simulation regression CI<br/>GitHub Actions workflow<br/>[sim_regression.yml]"]
end

subgraph group_deployment["Model Build &amp; Deployment"]
  node_simulink_build["INS Simulink model build<br/>model integration"]
  node_embedded_codegen["Embedded Coder target<br/>ARM Cortex-M C/C++ generation"]
end

node_init -->|"loads contracts"| node_interfaces
node_init -->|"initializes runtime"| node_scheduler
node_interfaces -->|"rates and buses"| node_scheduler
node_scheduler -->|"scheduled execution"| node_guidance
node_scheduler -->|"scheduled execution"| node_control
node_scheduler -->|"timestamped measurements"| node_estimator
node_guidance -->|"trajectory and setpoints"| node_control
node_estimator -->|"measurement updates"| node_ekf_core
node_ekf_core -->|"estimated state"| node_control
node_control -->|"wrench demands"| node_allocation
node_allocation -->|"actuator commands"| node_plant
node_thrust_lut -->|"propulsion lookup"| node_plant
node_plant -->|"vehicle state"| node_sensors
node_sensors -->|"asynchronous sensor data"| node_scheduler
node_estimator -->|"innovation and health"| node_fdir
node_allocation -->|"actuation health"| node_fdir
node_fdir -.->|"override mission progression"| node_guidance
node_fdir -.->|"degraded / fallback commands"| node_control
node_simulink_build -->|"integrates runtime"| node_scheduler
node_simulink_build -->|"integrates simulation"| node_plant
node_validation -->|"drives scenarios"| node_simulink_build
node_trim_linearize -->|"analyzes dynamics"| node_plant
node_plant -->|"simulation outputs"| node_logging
node_estimator -->|"navigation outputs"| node_logging
node_validation -->|"campaign results"| node_logging
node_embedded_codegen -->|"generates from model"| node_simulink_build
node_ci -->|"runs regression"| node_validation

click node_init "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Runtime/init_all.m"
click node_interfaces "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Interfaces/bus_definitions.m"
click node_scheduler "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Runtime/task_scheduler.m"
click node_guidance "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Guidance/generate_trajectory.m"
click node_control "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Control/gain_schedule_hover_forwardflight.m"
click node_allocation "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Control/control_allocation_matrix.m"
click node_estimator "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Estimator/main_advanced_ins.m"
click node_ekf_core "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Estimator/advanced_ekf_core.m"
click node_fdir "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Faults/fallback_supervisor_matrix.m"
click node_plant "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Plant/motor_esc_dynamics.m"
click node_thrust_lut "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Plant/thrust_torque_lut.m"
click node_sensors "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Sensors/simulate_imu.m"
click node_simulink_build "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Codegen/build_ins_simulink_model.m"
click node_validation "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Validation/stress_campaign_runner.m"
click node_trim_linearize "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Validation/trim_and_linearize.m"
click node_logging "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Logs/telemetry_packetizer.m"
click node_embedded_codegen "https://github.com/arya-mgc/ins-system-for-drone/blob/main/Codegen/setup_embedded_coder.m"
click node_ci "https://github.com/arya-mgc/ins-system-for-drone/blob/main/.github/workflows/sim_regression.yml"

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_init,node_interfaces,node_scheduler toneBlue
class node_guidance,node_control,node_allocation,node_estimator,node_ekf_core,node_fdir toneAmber
class node_plant,node_thrust_lut,node_sensors toneMint
class node_validation,node_trim_linearize,node_logging,node_ci toneRose
class node_simulink_build,node_embedded_codegen toneIndigo
```

## Components

### Runtime & Interfaces

Multi-rate contracts and scheduling boundary.

- [Workspace initialization](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Runtime/init_all.m): MATLAB entry point · `Runtime/init_all.m`
- [Signal contracts](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Interfaces/bus_definitions.m): bus / enum / rate definitions · Defines cross-domain signals, units, and sample rates. · `Interfaces/bus_definitions.m`
- [Multi-rate scheduler](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Runtime/task_scheduler.m): discrete-time runtime · Coordinates rates, timestamps, and injected latency. · `Runtime/task_scheduler.m`

### Flight Stack

Guidance, control, estimation, and safety logic.

- [Mission guidance](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Guidance/generate_trajectory.m): trajectory & replanning · Converts mission state into constrained references. · `Guidance/generate_trajectory.m`
- [Feedback control](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Control/gain_schedule_hover_forwardflight.m): scheduled PID/LQR control · Produces actuator demands with limiting and anti-windup. · `Control/gain_schedule_hover_forwardflight.m`
- [Control allocation](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Control/control_allocation_matrix.m): actuator mixer · `Control/control_allocation_matrix.m`
- [INS / 15-state EKF](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Estimator/main_advanced_ins.m): navigation estimator · Maintains navigation state from asynchronous measurements. · `Estimator/main_advanced_ins.m`
- [EKF core](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Estimator/advanced_ekf_core.m): state estimation kernel · Implements propagation, correction, resets, and dead reckoning. · `Estimator/advanced_ekf_core.m`
- [FDIR supervisor](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Faults/fallback_supervisor_matrix.m): safety supervisor · Selects degraded or fallback behavior from health signals. · `Faults/fallback_supervisor_matrix.m`

### Plant & Sensors

Nonlinear aircraft and measurement simulation.

- [Aircraft plant](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Plant/motor_esc_dynamics.m): nonlinear 6-DOF simulation · Models vehicle, propulsion, battery, and environment. · `Plant/motor_esc_dynamics.m`
- [Thrust / torque LUT](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Plant/thrust_torque_lut.m): propulsion model · `Plant/thrust_torque_lut.m`
- [Sensor simulation](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Sensors/simulate_imu.m): noisy degraded measurements · Applies IMU behavior, GPS dropout, and bias drift. · `Sensors/simulate_imu.m`

### Validation & Observability

Scenario verification and output adapters.

- [Scenario validation](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Validation/stress_campaign_runner.m): Monte Carlo & stress workflows · Runs adversarial performance and robustness campaigns. · `Validation/stress_campaign_runner.m`
- [Trim & linearization](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Validation/trim_and_linearize.m): analysis entry point · `Validation/trim_and_linearize.m`
- [Replay & telemetry](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Logs/telemetry_packetizer.m): output adapters · Exports replay, telemetry, CSV, and ULog outputs. · `Logs/telemetry_packetizer.m`
- [Simulation regression CI](https://github.com/arya-mgc/ins-system-for-drone/blob/main/.github/workflows/sim_regression.yml): GitHub Actions workflow · `.github/workflows/sim_regression.yml`

### Model Build & Deployment

Simulink assembly and embedded code generation.

- [INS Simulink model build](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Codegen/build_ins_simulink_model.m): model integration · Constructs the INS and Simulink integration. · `Codegen/build_ins_simulink_model.m`
- [Embedded Coder target](https://github.com/arya-mgc/ins-system-for-drone/blob/main/Codegen/setup_embedded_coder.m): ARM Cortex-M C/C++ generation · Produces MISRA-oriented embedded artifacts. · `Codegen/setup_embedded_coder.m`

## Connections

- Workspace initialization → Signal contracts: loads contracts
- Workspace initialization → Multi-rate scheduler: initializes runtime
- Signal contracts → Multi-rate scheduler: rates and buses
- Multi-rate scheduler → Mission guidance: scheduled execution
- Multi-rate scheduler → Feedback control: scheduled execution
- Multi-rate scheduler → INS / 15-state EKF: timestamped measurements
- Mission guidance → Feedback control: trajectory and setpoints
- INS / 15-state EKF → EKF core: measurement updates
- EKF core → Feedback control: estimated state
- Feedback control → Control allocation: wrench demands
- Control allocation → Aircraft plant: actuator commands
- Thrust / torque LUT → Aircraft plant: propulsion lookup
- Aircraft plant → Sensor simulation: vehicle state
- Sensor simulation → Multi-rate scheduler: asynchronous sensor data
- INS / 15-state EKF → FDIR supervisor: innovation and health
- Control allocation → FDIR supervisor: actuation health
- FDIR supervisor → Mission guidance: override mission progression
- FDIR supervisor → Feedback control: degraded / fallback commands
- INS Simulink model build → Multi-rate scheduler: integrates runtime
- INS Simulink model build → Aircraft plant: integrates simulation
- Scenario validation → INS Simulink model build: drives scenarios
- Trim & linearization → Aircraft plant: analyzes dynamics
- Aircraft plant → Replay & telemetry: simulation outputs
- INS / 15-state EKF → Replay & telemetry: navigation outputs
- Scenario validation → Replay & telemetry: campaign results
- Embedded Coder target → INS Simulink model build: generates from model
- Simulation regression CI → Scenario validation: runs regression
