How arya-mgc/ins-system-for-drone works
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: task_scheduler.m Multi-rate scheduler · motor_esc_dynamics.m Aircraft plant · gain_schedule_hover_forwardflight.m Feedback control · main_advanced_ins.m INS / 15-state EKF
Components 18
Runtime & Interfaces
Multi-rate contracts and scheduling boundary.
- Workspace initialization
Runtime/init_all.m - Signal contracts · Defines cross-domain signals, units, and sample rates.
Interfaces/bus_definitions.m - Multi-rate scheduler · Coordinates rates, timestamps, and injected latency.
Runtime/task_scheduler.m
Flight Stack
Guidance, control, estimation, and safety logic.
- Mission guidance · Converts mission state into constrained references.
Guidance/generate_trajectory.m - Feedback control · Produces actuator demands with limiting and anti-windup.
Control/gain_schedule_hover_forwardflight.m - Control allocation
Control/control_allocation_matrix.m - INS / 15-state EKF · Maintains navigation state from asynchronous measurements.
Estimator/main_advanced_ins.m - EKF core · Implements propagation, correction, resets, and dead reckoning.
Estimator/advanced_ekf_core.m - FDIR supervisor · Selects degraded or fallback behavior from health signals.
Faults/fallback_supervisor_matrix.m
Plant & Sensors
Nonlinear aircraft and measurement simulation.
- Aircraft plant · Models vehicle, propulsion, battery, and environment.
Plant/motor_esc_dynamics.m - Thrust / torque LUT
Plant/thrust_torque_lut.m - Sensor simulation · Applies IMU behavior, GPS dropout, and bias drift.
Sensors/simulate_imu.m
Validation & Observability
Scenario verification and output adapters.
- Scenario validation · Runs adversarial performance and robustness campaigns.
Validation/stress_campaign_runner.m - Trim & linearization
Validation/trim_and_linearize.m - Replay & telemetry · Exports replay, telemetry, CSV, and ULog outputs.
Logs/telemetry_packetizer.m - Simulation regression CI
.github/workflows/sim_regression.yml
Model Build & Deployment
Simulink assembly and embedded code generation.
- INS Simulink model build · Constructs the INS and Simulink integration.
Codegen/build_ins_simulink_model.m - Embedded Coder target · Produces MISRA-oriented embedded artifacts.
Codegen/setup_embedded_coder.m
Connections 27
- 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