Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

F-16 Nonlinear 6-DOF Simulation

MATLAB

Simulation pipeline

run_all

This builds the aero/thrust tables, builds and validates the open-loop model, then designs, builds, and validates the augmented (SAS) model end to end.

Running it step by step instead

make_tables                    % build data/*.mat + verification figures
quicktest                      % sanity check + open-loop figure

build_openloop_model           % build f16_openloop.slx
sim('f16_openloop')
outOL = validate_openloop;     % trim+modes, then native .slx vs plant_ode.m

outAug = validate_augmented;   % designs SAS gains, saves data/sas_gains.mat
build_augmented_model          % build f16_augmented.slx WITH those gains
outAug = validate_augmented;   % re-run: now also checks the built model
sim('f16_augmented')

The augmented model has to be built after validate_augmented has saved gains at least once, that's why it's called twice above. If you run build_augmented_model before any gains exist, it falls back to conservative defaults. Re-run validate_augmented and rebuild.

After editing params.m or regenerating tables, run clear all first so cached persistent values reload.

Exporting reference data for the C++ cross-checks

export_sil_reference          % open-loop plant, any time
export_sas_sil_reference      % closed-loop SAS trajectory, needs data/ sas_gains.mat, so run validate_augmented first

Both write CSVs into ../cpp/tests/ for the C++ side to read.

Timing / real-time characterization + step-size justification

benchmark_timing               % needs f16_openloop.slx built first;
                               % uses data/augmented_results.mat if present for a sharper step-size justification

Prints the step-size justification (derived from the fastest achieved closed-loop bandwidth), then times the raw .m chain and the compiled Simulink model, reporting mean/median/P95/P99/max/jitter and the sustained real-time rate. Writes ../cpp/tests/matlab_timing_reference.csv for the C++ benchmark to read.


C++

Build

mingw32-make

This builds five executables in bin/: run_openloop, run_augmented, sil_test, sas_sil_test, benchmark.

Run the demo apps

./bin/run_openloop

Integrates the open-loop plant from trim for 20s. Prints the final state (should barely have moved) and saves openloop_trajectory.csv.

./bin/run_augmented

Runs the aft-c.g. instability demo open-loop vs. closed-loop (SAS engaged) response to the same perturbation. Prints growing/damped verdicts and saves augmented_openloop.csv / augmented_closedloop.csv -- plot q_dps vs t from both on the same chart (Excel, Python/pandas, or MATLAB's readtable+plot all work) to see the divergent-vs-damped curves directly.

Run the SIL (software-in-the-loop) checks

./bin/sil_test

Always runs an internal trim/residual self-check. If tests/sil_reference.csv exists (from export_sil_reference in MATLAB), it also runs a genuine cross-language comparison against that reference and prints per-state differences.

./bin/sas_sil_test

Needs tests/sas_sil_reference.csv (from export_sas_sil_reference in MATLAB) to do anything -- without it, it just prints what to run and exits cleanly. With it, replays MATLAB's exact closed-loop trajectory step by step and compares.

No rebuild needed after regenerating either CSV, re-run the executable.

Run the timing/speedup benchmark

./bin/benchmark

Times the open-loop plant and the closed-loop (SAS-engaged) case, reporting mean/median/P95/P99/max/jitter and the sustained real-time rate for each. If tests/matlab_timing_reference.csv exists (from benchmark_timing in MATLAB), also prints the C++-vs-MATLAB speedup factor against both the raw .m chain and the compiled Simulink model baselines.

Clean up

make clean

Removes bin/ and any .csv output files.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages