Skip to content

Co-Simulation FMU Support#4

Merged
pbosetti merged 8 commits into
MADS-NET:develfrom
alterlleo:devel
Jun 10, 2026
Merged

Co-Simulation FMU Support#4
pbosetti merged 8 commits into
MADS-NET:develfrom
alterlleo:devel

Conversation

@alterlleo

Copy link
Copy Markdown
Contributor

Overview

When Simscape is used in the model, the ModelExchange FMU type may cause unexpected behaviour. For this reason, some changes are made in order to make the agent able to automatically adapt to the CoSimulation FMU type as well.

A standalone CoSimulation FMU can be obtained only if the model is configured to use a fixed-step solver. Variable-step solvers requires MATLAB RunTime

Changes

The changes are tested just on a Linux machine. Here's the outline of the changes:

  • Automatic detection of the FMU type: depending on the presence of either CoSimulation or ModelExchange fields in the .xml file, the corrisponding instantiation is performed;
  • Depending on the FMU type, the integration as well changes: the custom integrator is used in the ModelExchange case, otherwise the exported integrator that is embedded in the FMU is called;
  • The FMU type is printed on command line along with the other parameters at agent's start;
  • If the model exported as Co-Simulation runs a discrete system (such as a model of a motor controller board), the dt requires to be fixed. In order to do that, the attribute canHandleVariableCommunicationStepSize is checked and if a fixed step is used, then the agent loop runs at a fixed period. The period must be a multiple of the model solver's sample time

Trigger Integration With Fixed-Step

The execution of an FMU exported with a fixed-step solver requires time increments that are multiples of its sample time. To support asynchronous triggers from external agents, the trigger mode automatically manages time synchronization thanks to a dedicated accumulator variable (t_buffer).
When a trigger is received, the elapsed time is added to the t_buffer. The agent then computes the maximum number of discrete solver steps that can fit within the accumulated time. The FMU is stepped forward accordingly, and the remaining fractional time, that is insufficient to trigger a full solver step, is preserved inside the t_buffer. This residual is carried over to the next cycle, ensuring no drift over the long term.

Variable step dependency

The agent is able of detecting Variable-step CoSimulation FMUs, but they require the MATLAB Runtime to be present on the machine. This is because variable-step solvers rely on external shared libraries (such as libmwsl_cosim_service_deploy.so). Without further machine configurations, it fails to instantiate due to that dependency.

alterlleo and others added 8 commits May 22, 2026 23:40
An Enum class is implemented in order to get the current type of the selected FMU. Depending on the FMU nature, a different integration is performed: if model exchange, then the default custom explicit integrator is used and, if co-simulation, the exported solver is called
still not trigger mode
dt measured starting from number of steps, buffer to limit drift
@pbosetti
pbosetti merged commit ba4bea4 into MADS-NET:devel Jun 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants