Model-in-the-Loop Simulation
Run model-in-the-loop (MIL) simulation for a discrete-time controller. Set the base step, apply input scenarios, and inspect signal traces in PlotLab.
Model-in-the-loop (MIL) simulation runs the compiled representation of a control model on a fixed time grid. In Modeloop, the Rust runtime executes the model against a scenario so you can inspect controller behavior before testing generated C. For example, apply a step to a speed reference and inspect the resulting command and saturation over time. Try the workflow with the Moving Average quickstart.
Build configuration
A simulation runs a build: what participates, and the scheduling decisions that bind it together. In the build configuration you choose:
- What participates. A single model in isolation — even a flat one — or the full multi-model system.
- The scheduling order. Callbacks eligible at the same simulation instant execute in this order. It is part of the design — review changes to it like model changes.
- Timing. The solver’s base step and the simulation duration. Each periodic callback’s period is defined on the callback itself (default sample time is 10 ms; resolution is microseconds).
When you press Run, Modeloop compiles the build, executes it, and streams results back. There is no separate “prepare” step to keep in sync.
Scenario profiles
Model inputs are driven by scenario profiles — time-varying generators evaluated by the solver at every step and published to the input signals.
| Profile | Parameters | Behavior |
|---|---|---|
constant |
value |
Fixed value for the whole run |
sine |
amplitude, frequency, offset, phase |
offset + amplitude · sin(2π · frequency · t + phase) |
ramp |
initial_value, slope, start_time |
Holds the initial value, then increases linearly from start_time |
step |
initial/final value, step time | Discontinuous jump at a configurable time |
table |
list of (time, value) points |
Linear interpolation between points — arbitrary test waveforms |
Profiles are per-input and per-scenario, so one model can carry a library of scenarios: nominal operation, limit conditions, fault injection. table profiles are the general escape hatch — measured data or hand-crafted edge cases replayed exactly.
Choosing profiles for verification
constant— steady-state behavior, operating-point checks.step— transient response: rise time, overshoot, settling.sine— frequency response, attenuation, phase lag.ramp— rate-dependent behavior, saturation onset.table— recorded drive cycles, regression fixtures, fault sequences.
Execution
Each solver step follows the fixed sequence described in Model Execution:
- Scenario profiles are evaluated at the current time and published.
- Eligible callbacks execute in scheduling order; each reads the latest value of its inputs, computes in data-flow order, and publishes its outputs.
- Signals selected for measurement are recorded into traces.
- Time advances by the base step.
To repeat a run, keep the model revision, runtime, initial state, input profiles, and timing fixed. Use explicit tolerances when comparing floating-point traces from different execution targets. See software-in-the-loop testing.
Results
Turn on Enable Signal Measurement in Properties for the connections you want to inspect. Measurements are available as:
- Interactive plots — signal traces over time, directly in the environment.
- ASAM MDF4 results — every run is stored as a
.mf4measurement artifact with its time axis and named channels, ready for PlotLab and compatible measurement tooling. - CSV interoperability export — when explicitly requested, measurements can still be exported for spreadsheets or lightweight scripts.
Because signal names flow through unchanged from the model, a well-named model (guidelines) produces self-describing exports.
Runtime diagnostics
When the runtime detects a fatal execution error, it stops the run and reports a diagnostic. Use the diagnostic to identify the affected operation or signal and inspect the scenario that reached it. Typical causes include division by zero, an invalid input to a mathematical operation, or overflow. See the modeling guidelines for ways to express guards and limits.
From simulation to target
When the model behaves as expected in MIL, add assertions to your test scenarios. Then run the same inputs against the compiled C in software-in-the-loop testing. Keep the initial state, sample periods, input profiles, and tolerances consistent so differences in the results are meaningful. See embedded C code generation for the generated interfaces.
The Rust runtime study compares the Rust and historical Python runtimes on the same engineering models. It describes what was timed and which parts of the execution path differed in MIL and SIL.